@Test public void testBasicOneNode() throws Exception { AbstractSyncManager sync = syncManagers[0]; IStoreClient<Key, TBean> testClient = sync.getStoreClient("global", Key.class, TBean.class); Key k = new Key("com.bigswitch.bigsync.internal", "test"); TBean tb = new TBean("hello", 42); TBean tb2 = new TBean("hello", 84); TBean tb3 = new TBean("hello", 126); assertNotNull(testClient.get(k)); assertNull(testClient.get(k).getValue()); testClient.put(k, tb); Versioned<TBean> result = testClient.get(k); assertEquals(result.getValue(), tb); result.setValue(tb2); testClient.put(k, result); try { result.setValue(tb3); testClient.put(k, result); fail("Should get ObsoleteVersionException"); } catch (ObsoleteVersionException e) { // happy town } result = testClient.get(k); assertEquals(tb2, result.getValue()); }
@Test public void testIterator() throws Exception { AbstractSyncManager sync = syncManagers[0]; IStoreClient<Key, TBean> testClient = sync.getStoreClient("local", Key.class, TBean.class); HashMap<Key, TBean> testMap = new HashMap<Key, TBean>(); for (int i = 0; i < 100; i++) { Key k = new Key("com.bigswitch.bigsync.internal", "test" + i); TBean tb = new TBean("value", i); testMap.put(k, tb); testClient.put(k, tb); } int size = 0; try (IClosableIterator<Entry<Key, Versioned<TBean>>> iter = testClient.entries()) { while (iter.hasNext()) { Entry<Key, Versioned<TBean>> e = iter.next(); assertEquals(testMap.get(e.getKey()), e.getValue().getValue()); size += 1; } } assertEquals(testMap.size(), size); }