blob: f1e157d23501ad594d318d1fa96c036f312b4c0f [file] [log] [blame]
Jonathan Hart6df90172014-04-03 10:13:11 -07001package net.onrc.onos.core.datastore.hazelcast;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -07002
Jonathan Harta88fd242014-04-03 11:24:54 -07003import static org.junit.Assert.assertArrayEquals;
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotEquals;
6import static org.junit.Assert.assertNotNull;
7import static org.junit.Assert.assertNull;
8import static org.junit.Assert.assertTrue;
9import static org.junit.Assert.fail;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070010
11import java.nio.charset.StandardCharsets;
12import java.util.Map;
13import java.util.TreeMap;
Yuta HIGUCHI3e7994c2014-05-12 21:01:33 -070014import java.util.UUID;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070015
Jonathan Harta88fd242014-04-03 11:24:54 -070016import net.onrc.onos.core.datastore.IKVTable.IKVEntry;
Jonathan Hart6df90172014-04-03 10:13:11 -070017import net.onrc.onos.core.datastore.ObjectDoesntExistException;
18import net.onrc.onos.core.datastore.ObjectExistsException;
19import net.onrc.onos.core.datastore.WrongVersionException;
Jonathan Hart6df90172014-04-03 10:13:11 -070020import net.onrc.onos.core.datastore.hazelcast.HZTable.VersionedValue;
21import net.onrc.onos.core.datastore.utils.ByteArrayComparator;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070022
23import org.junit.After;
24import org.junit.Before;
25import org.junit.Ignore;
26import org.junit.Rule;
27import org.junit.Test;
28import org.junit.rules.TestName;
29
30public class HZTableTest {
31 @Rule
Ray Milkey269ffb92014-04-03 14:43:30 -070032 public TestName name = new TestName();
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070033
Yuta HIGUCHI3e7994c2014-05-12 21:01:33 -070034 static final String TEST_TABLE_NAME = "TableForUnitTest" + UUID.randomUUID();
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070035 HZTable table;
36
37 @Before
38 public void setUp() throws Exception {
Ray Milkey269ffb92014-04-03 14:43:30 -070039 table = (HZTable) HZClient.getClient().getTable(TEST_TABLE_NAME);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070040 }
41
42 @After
43 public void tearDown() throws Exception {
Ray Milkey269ffb92014-04-03 14:43:30 -070044 HZClient.getClient().dropTable(table);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070045 }
46
47 public void assertEntryInTable(final byte[] key, final byte[] value, final long version) {
Ray Milkey269ffb92014-04-03 14:43:30 -070048 VersionedValue valueblob = table.getBackendMap().get(key);
49 assertNotNull(valueblob);
50 assertArrayEquals(value, valueblob.getValue());
51 assertEquals(version, valueblob.getVersion());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070052 }
53
54 public void assertKeyNotInTable(final byte[] key) {
Ray Milkey269ffb92014-04-03 14:43:30 -070055 VersionedValue valueblob = table.getBackendMap().get(key);
56 assertNull(valueblob);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070057 }
58
59 @Test
60 public void testGetInitialVersion() {
Ray Milkey269ffb92014-04-03 14:43:30 -070061 final long version1 = HZTable.getInitialVersion();
62 assertNotEquals(HZClient.VERSION_NONEXISTENT, version1);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070063
Ray Milkey269ffb92014-04-03 14:43:30 -070064 final long version2 = HZTable.getInitialVersion();
65 assertNotEquals(HZClient.VERSION_NONEXISTENT, version2);
66 assertNotEquals(version1, version2);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070067 }
68
69 @Test
70 public void testGetNextVersion() {
Ray Milkey269ffb92014-04-03 14:43:30 -070071 final long nextVersion = HZTable.getNextVersion(1);
72 assertNotEquals(nextVersion, HZClient.VERSION_NONEXISTENT);
73 assertNotEquals(nextVersion, 1);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070074
Ray Milkey269ffb92014-04-03 14:43:30 -070075 final long nextVersion1 = HZTable.getNextVersion(Long.MAX_VALUE);
76 assertNotEquals(nextVersion1, HZClient.VERSION_NONEXISTENT);
77 assertNotEquals(nextVersion1, Long.MAX_VALUE);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070078
Ray Milkey269ffb92014-04-03 14:43:30 -070079 final long nextVersion11 = HZTable.getNextVersion(HZClient.VERSION_NONEXISTENT - 1);
80 assertNotEquals(nextVersion11, HZClient.VERSION_NONEXISTENT);
81 assertNotEquals(nextVersion11, HZClient.VERSION_NONEXISTENT - 1);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070082 }
83
84 @Ignore // nothing to test for now
85 @Test
86 public void testHZTable() {
Ray Milkey269ffb92014-04-03 14:43:30 -070087 fail("Not yet implemented");
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070088 }
89
90 @Test
91 public void testGetTableName() {
Ray Milkey269ffb92014-04-03 14:43:30 -070092 assertEquals(TEST_TABLE_NAME, table.getTableName());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070093 }
94
95 @Test
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070096 public void testVersionNonexistant() {
Ray Milkey7531a342014-04-11 15:08:12 -070097 assertEquals(HZClient.VERSION_NONEXISTENT, table.getVersionNonexistant());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070098 }
99
100 @Test
101 public void testGetTableId() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700102 // for Hazelcast implementation IKVTableID is table itself
103 assertEquals(table, table.getTableId());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700104 }
105
106 @Test
107 public void testCreate() throws ObjectExistsException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700108 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
109 final byte[] value = "SomeValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700110
Ray Milkey269ffb92014-04-03 14:43:30 -0700111 final long version = table.create(key, value);
112 assertNotEquals(HZClient.VERSION_NONEXISTENT, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700113
Ray Milkey269ffb92014-04-03 14:43:30 -0700114 assertEntryInTable(key, value, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700115 }
116
117 @Test(expected = ObjectExistsException.class)
118 public void testCreateConflict() throws ObjectExistsException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700119 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
120 final byte[] value = "SomeValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700121
Ray Milkey269ffb92014-04-03 14:43:30 -0700122 final long version = table.create(key, value);
123 assertNotEquals(HZClient.VERSION_NONEXISTENT, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700124
Ray Milkey269ffb92014-04-03 14:43:30 -0700125 assertEntryInTable(key, value, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700126
Ray Milkey269ffb92014-04-03 14:43:30 -0700127 table.create(key, value);
128 fail("Should have thrown exception");
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700129 }
130
131 @Test
132 public void testForceCreate() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700133 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
134 final byte[] value = "SomeValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700135
Ray Milkey269ffb92014-04-03 14:43:30 -0700136 final long version = table.forceCreate(key, value);
137 assertNotEquals(HZClient.VERSION_NONEXISTENT, version);
138 assertEntryInTable(key, value, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700139
140
Ray Milkey269ffb92014-04-03 14:43:30 -0700141 final long version1 = table.forceCreate(key, value);
142 assertNotEquals(HZClient.VERSION_NONEXISTENT, version1);
143 assertNotEquals(version, version1);
144 assertEntryInTable(key, value, version1);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700145 }
146
147 @Test
148 public void testRead() throws ObjectDoesntExistException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700149 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
150 final byte[] value = "SomeValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700151
Ray Milkey269ffb92014-04-03 14:43:30 -0700152 // put data to read
153 final long version = table.forceCreate(key, value);
154 assertNotEquals(HZClient.VERSION_NONEXISTENT, version);
155 assertEntryInTable(key, value, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700156
Ray Milkey269ffb92014-04-03 14:43:30 -0700157 // test body
158 final IKVEntry readValue = table.read(key);
159 assertArrayEquals(key, readValue.getKey());
160 assertArrayEquals(value, readValue.getValue());
161 assertEquals(version, readValue.getVersion());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700162 }
163
164
165 @Test(expected = ObjectDoesntExistException.class)
166 public void testReadNotExist() throws ObjectDoesntExistException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700167 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700168
Ray Milkey269ffb92014-04-03 14:43:30 -0700169 table.read(key);
170 fail("Should have thrown exception");
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700171 }
172
173 @Test
174 public void testUpdateByteArrayByteArrayLongSuccess() throws ObjectDoesntExistException, WrongVersionException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700175 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
176 final byte[] oldValue = "OldValue".getBytes(StandardCharsets.UTF_8);
177 final byte[] value = "SomeValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700178
Ray Milkey269ffb92014-04-03 14:43:30 -0700179 // put data to update
180 final long oldVersion = table.forceCreate(key, oldValue);
181 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
182 assertEntryInTable(key, oldValue, oldVersion);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700183
Ray Milkey269ffb92014-04-03 14:43:30 -0700184 final long version = table.update(key, value, oldVersion);
185 assertNotEquals(HZClient.VERSION_NONEXISTENT, version);
186 assertEntryInTable(key, value, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700187 }
188
189 @Test(expected = ObjectDoesntExistException.class)
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700190 public void testUpdateByteArrayByteArrayLongFailNoOldValue()
191 throws ObjectDoesntExistException, WrongVersionException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700192 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
193 final byte[] value = "SomeValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700194
Ray Milkey269ffb92014-04-03 14:43:30 -0700195 final long oldVersion = 0xDEAD;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700196
Ray Milkey269ffb92014-04-03 14:43:30 -0700197 final long version = table.update(key, value, oldVersion);
198 assertNotEquals(HZClient.VERSION_NONEXISTENT, version);
199 assertEntryInTable(key, value, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700200 }
201
202 @Test(expected = WrongVersionException.class)
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700203 public void testUpdateByteArrayByteArrayLongFailWrongVersion()
204 throws ObjectDoesntExistException, WrongVersionException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700205 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
206 final byte[] oldValue = "OldValue".getBytes(StandardCharsets.UTF_8);
207 final byte[] value = "SomeValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700208
Ray Milkey269ffb92014-04-03 14:43:30 -0700209 // put data to update
210 final long oldVersion = table.forceCreate(key, oldValue);
211 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
212 assertEntryInTable(key, oldValue, oldVersion);
213 // some one updates (from different thread/process in reality)
214 table.forceCreate(key, oldValue);
215 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700216
217
Ray Milkey269ffb92014-04-03 14:43:30 -0700218 table.update(key, value, oldVersion);
219 fail("Should have thrown exception");
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700220 }
221
222 @Test
223 public void testUpdateByteArrayByteArraySuccess() throws ObjectDoesntExistException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700224 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
225 final byte[] oldValue = "OldValue".getBytes(StandardCharsets.UTF_8);
226 final byte[] value = "SomeValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700227
Ray Milkey269ffb92014-04-03 14:43:30 -0700228 // put data to update
229 final long oldVersion = table.forceCreate(key, oldValue);
230 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
231 assertEntryInTable(key, oldValue, oldVersion);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700232
Ray Milkey269ffb92014-04-03 14:43:30 -0700233 final long version = table.update(key, value);
234 assertNotEquals(HZClient.VERSION_NONEXISTENT, version);
235 assertEntryInTable(key, value, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700236 }
237
238 @Test(expected = ObjectDoesntExistException.class)
239 public void testUpdateByteArrayByteArrayFailNoOldValue() throws ObjectDoesntExistException, WrongVersionException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700240 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
241 final byte[] value = "SomeValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700242
Ray Milkey269ffb92014-04-03 14:43:30 -0700243 final long version = table.update(key, value);
244 assertNotEquals(HZClient.VERSION_NONEXISTENT, version);
245 assertEntryInTable(key, value, version);
246 fail("Should have thrown exception");
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700247 }
248
249 @Test
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700250 public void testUpdateByteArrayByteArraySuccessIgnoreVersion()
251 throws ObjectDoesntExistException, WrongVersionException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700252 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
253 final byte[] oldValue = "OldValue".getBytes(StandardCharsets.UTF_8);
254 final byte[] value = "SomeValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700255
Ray Milkey269ffb92014-04-03 14:43:30 -0700256 // put data to update
257 final long oldVersion = table.forceCreate(key, oldValue);
258 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
259 assertEntryInTable(key, oldValue, oldVersion);
260 // someone updates (from different thread/process in reality)
261 table.forceCreate(key, oldValue);
262 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700263
264
Ray Milkey269ffb92014-04-03 14:43:30 -0700265 final long version = table.update(key, value);
266 assertNotEquals(HZClient.VERSION_NONEXISTENT, version);
267 assertEntryInTable(key, value, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700268 }
269
270 @Test
271 public void testDelete() throws ObjectDoesntExistException, WrongVersionException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700272 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
273 final byte[] oldValue = "OldValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700274
Ray Milkey269ffb92014-04-03 14:43:30 -0700275 // put data to delete
276 final long oldVersion = table.forceCreate(key, oldValue);
277 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
278 assertEntryInTable(key, oldValue, oldVersion);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700279
Ray Milkey269ffb92014-04-03 14:43:30 -0700280 long version = table.delete(key, oldVersion);
281 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
282 assertEquals(oldVersion, version);
283 assertKeyNotInTable(key);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700284 }
285
286 @Test(expected = ObjectDoesntExistException.class)
287 public void testDeleteFailNoEntry() throws ObjectDoesntExistException, WrongVersionException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700288 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700289
Ray Milkey269ffb92014-04-03 14:43:30 -0700290 final long oldVersion = 0xDEAD;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700291
Ray Milkey269ffb92014-04-03 14:43:30 -0700292 try {
293 table.delete(key, oldVersion);
294 } catch (ObjectDoesntExistException | WrongVersionException e) {
295 assertKeyNotInTable(key);
296 throw e;
297 }
298 fail("Should have thrown exception");
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700299 }
300
301 @Test(expected = WrongVersionException.class)
302 public void testDeleteFailWrongVersion() throws ObjectDoesntExistException, WrongVersionException {
Ray Milkey269ffb92014-04-03 14:43:30 -0700303 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
304 final byte[] oldValue = "OldValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700305
Ray Milkey269ffb92014-04-03 14:43:30 -0700306 // put data to delete
307 final long oldVersion = table.forceCreate(key, oldValue);
308 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
309 assertEntryInTable(key, oldValue, oldVersion);
310 // someone updates (from different thread/process in reality)
311 final long latestVersion = table.forceCreate(key, oldValue);
312 assertNotEquals(HZClient.VERSION_NONEXISTENT, latestVersion);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700313
Ray Milkey269ffb92014-04-03 14:43:30 -0700314 try {
315 table.delete(key, oldVersion);
316 } catch (ObjectDoesntExistException | WrongVersionException e) {
317 assertEntryInTable(key, oldValue, latestVersion);
318 throw e;
319 }
320 fail("Should have thrown exception");
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700321 }
322
323
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700324 @Test
325 public void testForceDelete() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700326 final byte[] key = name.getMethodName().getBytes(StandardCharsets.UTF_8);
327 final byte[] oldValue = "OldValue".getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700328
Ray Milkey269ffb92014-04-03 14:43:30 -0700329 // put data to delete
330 final long oldVersion = table.forceCreate(key, oldValue);
331 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
332 assertEntryInTable(key, oldValue, oldVersion);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700333
Ray Milkey269ffb92014-04-03 14:43:30 -0700334 long version = table.forceDelete(key);
335 assertNotEquals(HZClient.VERSION_NONEXISTENT, oldVersion);
336 assertEquals(oldVersion, version);
337 assertKeyNotInTable(key);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700338 }
339
340 @Test
341 public void testGetAllEntries() {
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700342 final int dataSetSize = 100;
Ray Milkey269ffb92014-04-03 14:43:30 -0700343 final Map<byte[], VersionedValue> testdata = new TreeMap<>(ByteArrayComparator.BYTEARRAY_COMPARATOR);
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700344 for (int i = 0; i < dataSetSize; ++i) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700345 final byte[] key = (name.getMethodName() + i).getBytes(StandardCharsets.UTF_8);
346 final byte[] value = ("Value" + i).getBytes(StandardCharsets.UTF_8);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700347
Ray Milkey269ffb92014-04-03 14:43:30 -0700348 // put data to delete
349 final long version = table.forceCreate(key, value);
350 assertNotEquals(HZClient.VERSION_NONEXISTENT, version);
351 assertEntryInTable(key, value, version);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700352
Ray Milkey269ffb92014-04-03 14:43:30 -0700353 testdata.put(key, new VersionedValue(value, version));
354 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700355
Ray Milkey269ffb92014-04-03 14:43:30 -0700356 Iterable<IKVEntry> datastore = table.getAllEntries();
357 for (IKVEntry entry : datastore) {
358 VersionedValue expectedValue = testdata.get(entry.getKey());
359 assertNotNull(expectedValue);
360 assertArrayEquals(expectedValue.getValue(), entry.getValue());
361 assertEquals(expectedValue.getVersion(), entry.getVersion());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700362
Ray Milkey269ffb92014-04-03 14:43:30 -0700363 testdata.remove(entry.getKey());
364 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700365
Ray Milkey269ffb92014-04-03 14:43:30 -0700366 assertTrue(testdata.isEmpty());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700367 }
368
369 @Test
370 public void testToString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700371 assertEquals("[HZTable " + TEST_TABLE_NAME + "]", table.toString());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700372 }
373
374}