ClonedSyncPolicyCreator implements SyncPolicyCreator { @Override public SyncPolicy create(String sensor, WriterConfiguration config) { try { syncPolicy.reset(); byte[] serializedForm = SerDeUtils.toBytes(syncPolicy); return SerDeUtils.fromBytes(serializedForm, SyncPolicy.class); } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } } ClonedSyncPolicyCreator(SyncPolicy policy); @Override SyncPolicy create(String sensor, WriterConfiguration config);  }
@Test public void testClonedPolicy() { CountSyncPolicy basePolicy = new CountSyncPolicy(5); ClonedSyncPolicyCreator creator = new ClonedSyncPolicyCreator(basePolicy); SyncPolicy clonedPolicy = creator.create("blah", null); for(int i = 0;i < 4;++i) { assertFalse(clonedPolicy.mark(null, i)); } assertTrue(clonedPolicy.mark(null, 5)); clonedPolicy = creator.create("blah", null); assertFalse(clonedPolicy.mark(null, 0)); }