@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 testNotify() throws Exception { IStoreClient<String, String> client0 = syncManagers[0].getStoreClient("local", String.class, String.class); IStoreClient<String, String> client2 = syncManagers[2].getStoreClient( "local", new TypeReference<String>() {}, new TypeReference<String>() {}); TestListener t0 = new TestListener(); TestListener t2 = new TestListener(); client0.addStoreListener(t0); client2.addStoreListener(t2); client0.put("test0", "value"); client2.put("test2", "value"); HashSet<Update> c0 = new HashSet<Update>(); c0.add(new Update("test0", UpdateType.LOCAL)); c0.add(new Update("test2", UpdateType.REMOTE)); HashSet<Update> c2 = new HashSet<Update>(); c2.add(new Update("test0", UpdateType.REMOTE)); c2.add(new Update("test2", UpdateType.LOCAL)); waitForNotify(t0, c0, 2000); waitForNotify(t2, c2, 2000); assertEquals(2, t0.notified.size()); assertEquals(2, t2.notified.size()); t0.notified.clear(); t2.notified.clear(); Versioned<String> v0 = client0.get("test0"); v0.setValue("newvalue"); client0.put("test0", v0); Versioned<String> v2 = client0.get("test2"); v2.setValue("newvalue"); client2.put("test2", v2); waitForNotify(t0, c0, 2000); waitForNotify(t2, c2, 2000); assertEquals(2, t0.notified.size()); assertEquals(2, t2.notified.size()); t0.notified.clear(); t2.notified.clear(); client0.delete("test0"); client2.delete("test2"); waitForNotify(t0, c0, 2000); waitForNotify(t2, c2, 2000); assertEquals(2, t0.notified.size()); assertEquals(2, t2.notified.size()); }