1 package org.apache.commons.jcs.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 junit.framework.TestCase;
25
26 import org.apache.commons.jcs.auxiliary.disk.jdbc.TableState;
27 import org.apache.commons.jcs.auxiliary.disk.jdbc.dsfactory.SharedPoolDataSourceFactory;
28 import org.apache.commons.jcs.engine.control.CompositeCacheManager;
29
30 /**
31 * Simple tests for the MySQLDisk Cache.
32 * <p>
33 * We will probably need to setup an hsql behind this, to test some of the pass through methods.
34 * <p>
35 * @author Aaron Smuts
36 */
37 public class MySQLDiskCacheUnitTest
38 extends TestCase
39 {
40 /**
41 * Verify that we simply return null on get if an optimization is in
42 * progress and the cache is configured to balk on optimization.
43 * <p>
44 * This is a bit tricky since we don't want to have to have a mysql instance
45 * running. Right now this doesn't really test much
46 * @throws SQLException
47 */
48 public void testBalkOnGet() throws SQLException
49 {
50 // SETUP
51 MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes();
52 String tableName = "JCS_TEST";
53 // Just use something that exists
54 attributes.setDriverClassName( "org.hsqldb.jdbcDriver" );
55 attributes.setTableName( tableName );
56 attributes.setBalkDuringOptimization( true );
57 SharedPoolDataSourceFactory dsFactory = new SharedPoolDataSourceFactory();
58 dsFactory.initialize(attributes);
59
60 TableState tableState = new TableState( tableName );
61 tableState.setState( TableState.OPTIMIZATION_RUNNING );
62
63 MySQLDiskCache<String, String> cache = new MySQLDiskCache<String, String>( attributes, dsFactory, tableState,
64 CompositeCacheManager.getUnconfiguredInstance() );
65
66 // DO WORK
67 Object result = cache.processGet( "myKey" );
68
69 // VERIFY
70 assertNull( "The result should be null", result );
71 }
72 }