@Test public void testCloneIntegrity() { CacheResponse actor = Actor.getReference(CacheResponse.class, UUID.randomUUID().toString()); // Initialize a dto int someIdValue = 3214; TestDto1 a = new TestDto1(); a.setSampleInt(someIdValue); a.getSampleIntList().addAll(Arrays.asList(10, 20, 20, 30, 40, 50)); a.setSampleActor(actor); // Place dto in actor actor.setDto1(a).join(); // Get dto from actor, caching it TestDto1 a1 = actor.getDto1().join(); // Modify our copy of the cached dto a1.setSampleInt(someIdValue + 10); a1.getSampleIntList().remove((Object) 30); a1.getSampleIntList().add(60); a1.getSampleIntList().add(70); // Get dto from cache TestDto1 a2 = actor.getDto1().join(); // Verify that the cached dto is unchanged assertEquals(someIdValue, a2.getSampleInt()); if (stage.getObjectCloner() instanceof JavaSerializationCloner) { assertEquals(a1.getId(), a2.getId()); } else { assertSame(a1.getId(), a2.getId()); } assertNotEquals(a1.getSampleIntList().size(), a2.getSampleIntList().size()); assertTrue(a2.getSampleIntList().contains(30)); assertFalse(a2.getSampleIntList().contains(60)); assertFalse(a2.getSampleIntList().contains(70)); assertNotSame(a1, a2); }
@Test public void testCloneCyclicReference() { // Set up cyclic reference TestDto1 a = new TestDto1(); TestDto2 b = new TestDto2(); a.setDto2(b); b.setDto1(a); assertSame(a, b.getDto1()); // Send to actor CacheResponse actor = Actor.getReference(CacheResponse.class, UUID.randomUUID().toString()); actor.setDto1(a).join(); // Get dto from cache and test cyclic reference TestDto1 a1 = actor.getDto1().join(); assertSame(a1, a1.getDto2().getDto1()); assertNotSame(a, a1); }