View Javadoc
1   package org.apache.commons.jcs3.engine;
2   
3   import org.apache.commons.jcs3.auxiliary.remote.MockRemoteCacheListener;
4   import org.apache.commons.jcs3.engine.behavior.ICacheEventQueue;
5   import org.apache.commons.jcs3.engine.behavior.ICacheListener;
6   import org.apache.commons.jcs3.engine.behavior.ICacheEventQueue.QueueType;
7   
8   /*
9    * Licensed to the Apache Software Foundation (ASF) under one
10   * or more contributor license agreements.  See the NOTICE file
11   * distributed with this work for additional information
12   * regarding copyright ownership.  The ASF licenses this file
13   * to you under the Apache License, Version 2.0 (the
14   * "License"); you may not use this file except in compliance
15   * with the License.  You may obtain a copy of the License at
16   *
17   *   http://www.apache.org/licenses/LICENSE-2.0
18   *
19   * Unless required by applicable law or agreed to in writing,
20   * software distributed under the License is distributed on an
21   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22   * KIND, either express or implied.  See the License for the
23   * specific language governing permissions and limitations
24   * under the License.
25   */
26  
27  import junit.framework.TestCase;
28  
29  /** Unit tests for the CacheEventQueueFactory */
30  public class CacheEventQueueFactoryUnitTest
31      extends TestCase
32  {
33      /** Test create */
34      public void testCreateCacheEventQueue_Single()
35      {
36          // SETUP
37          final QueueType eventQueueType = QueueType.SINGLE;
38          final ICacheListener<String, String> listener = new MockRemoteCacheListener<>();
39          final long listenerId = 1;
40  
41          final CacheEventQueueFactory<String, String> factory = new CacheEventQueueFactory<>();
42  
43          // DO WORK
44          final ICacheEventQueue<String, String> result = factory.createCacheEventQueue( listener, listenerId, "cacheName", "threadPoolName", eventQueueType );
45  
46          // VERIFY
47          assertNotNull( "Should have a result", result );
48          assertTrue( "Wrong type", result.getQueueType() == QueueType.SINGLE );
49      }
50  
51      /** Test create */
52      public void testCreateCacheEventQueue_Pooled()
53      {
54          // SETUP
55          final QueueType eventQueueType = QueueType.POOLED;
56          final ICacheListener<String, String> listener = new MockRemoteCacheListener<>();
57          final long listenerId = 1;
58  
59          final CacheEventQueueFactory<String, String> factory = new CacheEventQueueFactory<>();
60  
61          // DO WORK
62          final ICacheEventQueue<String, String> result = factory.createCacheEventQueue( listener, listenerId, "cacheName", "threadPoolName", eventQueueType );
63  
64          // VERIFY
65          assertNotNull( "Should have a result", result );
66          assertTrue( "Wrong type", result.getQueueType() == QueueType.POOLED );
67      }
68  }