8
8
import org .terracotta .toolkit .builder .ToolkitCacheConfigBuilder ;
9
9
import org .terracotta .toolkit .config .Configuration ;
10
10
import org .terracotta .toolkit .internal .cache .VersionedValue ;
11
+ import org .terracotta .toolkit .internal .store .ConfigFieldsInternal ;
11
12
12
13
import com .google .common .collect .HashMultimap ;
13
14
import com .google .common .collect .Maps ;
24
25
import com .terracotta .toolkit .bulkload .BufferedOperation ;
25
26
import com .terracotta .toolkit .collections .servermap .api .ServerMapLocalStoreFactory ;
26
27
import com .terracotta .toolkit .factory .impl .ToolkitCacheDistributedTypeFactory ;
28
+ import com .terracotta .toolkit .object .serialization .CustomLifespanSerializedMapValue ;
27
29
import com .terracotta .toolkit .object .serialization .SerializationStrategy ;
28
30
import com .terracotta .toolkit .object .serialization .SerializedMapValue ;
29
31
import com .terracotta .toolkit .rejoin .PlatformServiceProvider ;
40
42
import static org .junit .Assert .assertEquals ;
41
43
import static org .mockito .Matchers .any ;
42
44
import static org .mockito .Matchers .anyBoolean ;
45
+ import static org .mockito .Matchers .anyInt ;
43
46
import static org .mockito .Matchers .eq ;
44
47
import static org .mockito .Matchers .isNull ;
45
48
import static org .mockito .Mockito .mock ;
@@ -76,8 +79,7 @@ public void setUp() throws Exception {
76
79
77
80
@ Test
78
81
public void testCreateRemoveBufferedOperation () throws Exception {
79
- ServerMap serverMap = new ServerMap (configuration , "foo" );
80
- serverMap .__tc_managed (tcObjectServerMap );
82
+ ServerMap serverMap = getServerMap ();
81
83
82
84
BufferedOperation bo = serverMap .createBufferedOperation (BufferedOperation .Type .REMOVE , "foo" , null , 1 , 2 , 3 , 4 );
83
85
assertThat (bo .getType (), is (BufferedOperation .Type .REMOVE ));
@@ -87,8 +89,7 @@ public void testCreateRemoveBufferedOperation() throws Exception {
87
89
88
90
@ Test
89
91
public void testCreatePutIfAbsentBufferedOperation () throws Exception {
90
- ServerMap serverMap = new ServerMap (configuration , "foo" );
91
- serverMap .__tc_managed (tcObjectServerMap );
92
+ ServerMap serverMap = getServerMap ();
92
93
93
94
BufferedOperation <String > bo = serverMap .createBufferedOperation (BufferedOperation .Type .PUT_IF_ABSENT , "foo" , "bar" , 1 , 2 , 3 , 4 );
94
95
assertThat (bo .getType (), is (BufferedOperation .Type .PUT_IF_ABSENT ));
@@ -101,8 +102,7 @@ public void testCreatePutIfAbsentBufferedOperation() throws Exception {
101
102
102
103
@ Test
103
104
public void testCreatePutBufferedOperation () throws Exception {
104
- ServerMap serverMap = new ServerMap (configuration , "foo" );
105
- serverMap .__tc_managed (tcObjectServerMap );
105
+ ServerMap serverMap = getServerMap ();
106
106
107
107
BufferedOperation <String > bo = serverMap .createBufferedOperation (BufferedOperation .Type .PUT , "foo" , "bar" , 4 , 3 , 2 , 1 );
108
108
assertThat (bo .getType (), is (BufferedOperation .Type .PUT ));
@@ -115,8 +115,7 @@ public void testCreatePutBufferedOperation() throws Exception {
115
115
116
116
@ Test
117
117
public void testDrain () throws Exception {
118
- ServerMap serverMap = new ServerMap (configuration , "foo" );
119
- serverMap .__tc_managed (tcObjectServerMap );
118
+ ServerMap serverMap = getServerMap ();
120
119
121
120
Map <String , BufferedOperation <String >> operations = new HashMap <String , BufferedOperation <String >>();
122
121
operations .put ("foo" , serverMap .createBufferedOperation (BufferedOperation .Type .PUT , "foo" , "bar" , 4 , 3 , 2 , 1 ));
@@ -131,27 +130,37 @@ public void testDrain() throws Exception {
131
130
132
131
@ Test
133
132
public void testGetAllVersioned () throws Exception {
134
- ServerMap serverMap = new ServerMap (configuration , "foo" );
135
- serverMap .__tc_managed (tcObjectServerMap );
133
+ ServerMap serverMap = getServerMap ();
136
134
137
135
SetMultimap <ObjectID , Object > request = HashMultimap .create ();
138
136
request .putAll (new ObjectID (1 ), Sets .<Object >newHashSet ("a" , "b" ));
139
- request .putAll (new ObjectID (2 ), Sets .<Object >newHashSet ("c" , "d" ));
137
+ request .putAll (new ObjectID (2 ), Sets .<Object >newHashSet ("c" , "d" , "e" , "f" ));
140
138
141
139
Map <Object , Object > response = Maps .newHashMap ();
142
140
response .put ("a" , new VersionedObject (mockSerializedMapValue ("1" ), 1 ));
143
141
response .put ("b" , new VersionedObject (mockSerializedMapValue ("2" ), 2 ));
144
142
response .put ("c" , new VersionedObject (mockSerializedMapValue ("3" ), 3 ));
145
143
response .put ("d" , new VersionedObject (mockSerializedMapValue ("4" ), 4 ));
144
+ response .put ("e" , null );
145
+ response .put ("f" , new VersionedObject (mockSerializedMapValue ("5" , true ), 5 ));
146
146
147
147
when (tcObjectServerMap .getAllVersioned (request )).thenReturn (response );
148
148
149
149
Map <String , VersionedValue <String >> result = serverMap .getAllVersioned (request );
150
- assertEquals (4 , result .size ());
150
+ assertEquals (6 , result .size ());
151
151
assertThat (result , hasEntry ("a" , versionedValue ("1" , 1 )));
152
152
assertThat (result , hasEntry ("b" , versionedValue ("2" , 2 )));
153
153
assertThat (result , hasEntry ("c" , versionedValue ("3" , 3 )));
154
154
assertThat (result , hasEntry ("d" , versionedValue ("4" , 4 )));
155
+ assertThat (result , hasEntry ("e" , null ));
156
+ assertThat (result , hasEntry ("f" , null ));
157
+ }
158
+
159
+ private ServerMap getServerMap () {
160
+ ServerMap serverMap = new ServerMap (configuration , "foo" );
161
+ serverMap .__tc_managed (tcObjectServerMap );
162
+ serverMap .setLockStrategy (ConfigFieldsInternal .LOCK_STRATEGY .LONG_LOCK_STRATEGY );
163
+ return serverMap ;
155
164
}
156
165
157
166
private static <T > VersionedValue <T > versionedValue (T value , long version ) {
@@ -170,4 +179,12 @@ private static SerializedMapValue<String> mockSerializedMapValue(String value) t
170
179
.thenReturn (value );
171
180
return smv ;
172
181
}
182
+
183
+ private static SerializedMapValue <String > mockSerializedMapValue (String value , boolean expired ) throws IOException , ClassNotFoundException {
184
+ SerializedMapValue <String > smv = mock (CustomLifespanSerializedMapValue .class );
185
+ when (smv .getDeserializedValue (any (SerializationStrategy .class ), anyBoolean (), any (L1ServerMapLocalCacheStore .class ), any (), anyBoolean ()))
186
+ .thenReturn (value );
187
+ when (smv .isExpired (anyInt (), anyInt (), anyInt ())).thenReturn (expired );
188
+ return smv ;
189
+ }
173
190
}
0 commit comments