Search in sources :

Example 1 with DirtyTracker

use of org.hibernate.bytecode.enhance.internal.tracker.DirtyTracker in project hibernate-orm by hibernate.

the class DirtyTrackerTest method testSortedTracker.

@Test
public void testSortedTracker() {
    DirtyTracker tracker = new SortedFieldTracker();
    assertTrue(tracker.isEmpty());
    assertEquals(0, tracker.get().length);
    tracker.add("foo");
    assertFalse(tracker.isEmpty());
    assertArrayEquals(tracker.get(), new String[] { "foo" });
    tracker.clear();
    assertTrue(tracker.isEmpty());
    assertEquals(0, tracker.get().length);
    tracker.add("foo");
    tracker.add("bar");
    tracker.add("another.bar");
    tracker.add("foo");
    tracker.add("another.foo");
    tracker.add("another.bar");
    assertEquals(4, tracker.get().length);
    // the algorithm for this implementation relies on the fact that the array is kept sorted, so let's check it really is
    assertTrue(isSorted(tracker.get()));
    tracker.suspend(true);
    tracker.add("one more");
    assertEquals(4, tracker.get().length);
}
Also used : SortedFieldTracker(org.hibernate.bytecode.enhance.internal.tracker.SortedFieldTracker) DirtyTracker(org.hibernate.bytecode.enhance.internal.tracker.DirtyTracker) Test(org.junit.Test)

Example 2 with DirtyTracker

use of org.hibernate.bytecode.enhance.internal.tracker.DirtyTracker in project hibernate-orm by hibernate.

the class DirtyTrackerTest method testSimpleTracker.

@Test
public void testSimpleTracker() {
    DirtyTracker tracker = new SimpleFieldTracker();
    assertTrue(tracker.isEmpty());
    assertEquals(0, tracker.get().length);
    tracker.add("foo");
    assertFalse(tracker.isEmpty());
    assertArrayEquals(tracker.get(), new String[] { "foo" });
    tracker.clear();
    assertTrue(tracker.isEmpty());
    assertEquals(0, tracker.get().length);
    tracker.add("foo");
    tracker.add("bar");
    tracker.add("another.bar");
    tracker.add("foo");
    tracker.add("another.foo");
    tracker.add("another.bar");
    assertEquals(4, tracker.get().length);
    tracker.suspend(true);
    tracker.add("one more");
    assertEquals(4, tracker.get().length);
}
Also used : SimpleFieldTracker(org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker) DirtyTracker(org.hibernate.bytecode.enhance.internal.tracker.DirtyTracker) Test(org.junit.Test)

Aggregations

DirtyTracker (org.hibernate.bytecode.enhance.internal.tracker.DirtyTracker)2 Test (org.junit.Test)2 SimpleFieldTracker (org.hibernate.bytecode.enhance.internal.tracker.SimpleFieldTracker)1 SortedFieldTracker (org.hibernate.bytecode.enhance.internal.tracker.SortedFieldTracker)1