1 package org.apache.commons.jcs3.auxiliary.lateral;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.apache.commons.jcs3.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes;
7 import org.apache.commons.jcs3.engine.ZombieCacheServiceNonLocal;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import junit.framework.TestCase;
29
30
31
32
33 public class LateralCacheNoWaitFacadeUnitTest
34 extends TestCase
35 {
36 private LateralCacheNoWaitFacade<String, String> facade;
37 private LateralCache<String, String> cache;
38
39 @Override
40 protected void setUp() throws Exception
41 {
42
43 List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
44 TCPLateralCacheAttributes cattr = new TCPLateralCacheAttributes();
45 cattr.setCacheName( "testCache1" );
46 cattr.setTcpServer("localhost:7890");
47
48
49 facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
50 cache = new LateralCache<>(cattr, new ZombieCacheServiceNonLocal<>(), null);
51 }
52
53
54
55
56 public void testAddThenRemoveNoWait_InList()
57 {
58 LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
59
60
61 facade.addNoWait( noWait );
62
63
64 assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
65
66
67 facade.removeNoWait( noWait );
68
69
70 assertEquals( "Should have 0", 0, facade.getNoWaitSize() );
71 assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) );
72 }
73
74
75
76
77 public void testAddThenRemoveNoWait_InListSize2()
78 {
79 final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
80 noWait.setIdentityKey("1234");
81 final LateralCacheNoWait<String, String> noWait2 = new LateralCacheNoWait<>( cache );
82 noWait2.setIdentityKey("2345");
83
84
85 facade.addNoWait( noWait );
86 facade.addNoWait( noWait2 );
87
88
89 assertEquals( "Should have 2", 2, facade.getNoWaitSize() );
90 assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
91 assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) );
92
93
94 facade.removeNoWait( noWait );
95
96
97 assertEquals( "Should only have 1", 1, facade.getNoWaitSize() );
98 assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) );
99 assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) );
100 }
101
102
103
104
105 public void testAdd_InList()
106 {
107 final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
108
109
110 facade.addNoWait( noWait );
111 facade.addNoWait( noWait );
112
113
114 assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
115 assertEquals( "Should only have 1", 1, facade.getNoWaitSize() );
116 }
117
118
119
120
121 public void testAddThenRemoveNoWait_NotInList()
122 {
123 final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
124
125
126 facade.removeNoWait( noWait );
127
128
129 assertFalse( "Should not be in the list.", facade.containsNoWait( noWait ) );
130 }
131 }