1 package org.apache.commons.jcs3.auxiliary.disk.jdbc.mysql;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.sql.SQLException;
23
24 import org.apache.commons.jcs3.auxiliary.disk.jdbc.TableState;
25 import org.apache.commons.jcs3.auxiliary.disk.jdbc.dsfactory.SharedPoolDataSourceFactory;
26
27 import junit.framework.TestCase;
28
29 /**
30 * Simple tests for the MySQLDisk Cache.
31 * <p>
32 * We will probably need to setup an hsql behind this, to test some of the pass through methods.
33 * </p>
34 */
35 public class MySQLDiskCacheUnitTest
36 extends TestCase
37 {
38 /**
39 * Verify that we simply return null on get if an optimization is in
40 * progress and the cache is configured to balk on optimization.
41 * <p>
42 * This is a bit tricky since we don't want to have to have a mysql instance
43 * running. Right now this doesn't really test much
44 * </p>
45 * @throws SQLException
46 */
47 public void testBalkOnGet() throws SQLException
48 {
49 // SETUP
50 final MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes();
51 final String tableName = "JCS_TEST";
52 // Just use something that exists
53 attributes.setDriverClassName( "org.hsqldb.jdbcDriver" );
54 attributes.setTableName( tableName );
55 attributes.setBalkDuringOptimization( true );
56 final SharedPoolDataSourceFactory dsFactory = new SharedPoolDataSourceFactory();
57 dsFactory.initialize(attributes);
58
59 final TableState tableState = new TableState( tableName );
60 tableState.setState( TableState.OPTIMIZATION_RUNNING );
61
62 final MySQLDiskCache<String, String> cache = new MySQLDiskCache<>(attributes, dsFactory, tableState);
63
64 // DO WORK
65 final Object result = cache.processGet( "myKey" );
66
67 // VERIFY
68 assertNull( "The result should be null", result );
69 }
70 }