@Override public DeltaAware merge(DeltaAware d) { TestDeltaAware other = d instanceof TestDeltaAware ? (TestDeltaAware) d : new TestDeltaAware(); for (String componentName : changeLog.keySet()) { String componentValue = changeLog.get(componentName); if (componentName.equals("firstComponent")) { other.firstComponent = componentValue; } else if (componentName.equals("secondComponent")) { other.secondComponent = componentValue; } else { throw new RuntimeException("Unknown component: " + componentName); } } return other; } }
@Override public TestDeltaAware createObject(Cache cache, String key) { TestDeltaAware da = new TestDeltaAware(); da.setFirstComponent("first component of object with key=" + key); da.setSecondComponent("second component of object with key=" + key); cache.put(key, da); return da; }
@Test public void testPreloadOnStart() throws PersistenceException { Cache<Object, Object> cache = caches().get(0); TestDeltaAware value = new TestDeltaAware(); value.setFirstComponent("1st"); value.setSecondComponent("2nd"); cache.put(1, value); cache.stop(); cache.start(); TestDeltaAware deltaAware = (TestDeltaAware) cache.get(1); assertEquals("1st", deltaAware.getFirstComponent()); assertEquals("2nd", deltaAware.getSecondComponent()); }
private void doTest(MagicKey key) { cache(0).put(key, new TestDeltaAware()); Object response = cache(0).putIfAbsent(key, new TestDeltaAware()); assertEquals(TestDeltaAware.class, response.getClass()); ((TestDeltaAware) response).setFirstComponent("1"); ((TestDeltaAware) response).setSecondComponent("2"); response = cache(0).put(key, response); assertEquals(TestDeltaAware.class, response.getClass()); // The returned value should be the first one inserted in this test, which does not have the components set assertNull(((TestDeltaAware) response).getFirstComponent()); assertNull(((TestDeltaAware) response).getSecondComponent()); response = cache(0).get(key); assertEquals(TestDeltaAware.class, response.getClass()); assertEquals("1", ((TestDeltaAware) response).getFirstComponent()); assertEquals("2", ((TestDeltaAware) response).getSecondComponent()); } }