@Test
    public void testAddAndRemove() {
        SnapshotRegistry registry = new SnapshotRegistry(new LogContext());
        SnapshottableHashTable<TestElement> table =
            new SnapshottableHashTable<>(registry, 1);
        assertNull(table.snapshottableAddOrReplace(E_1B));
        assertEquals(1, table.snapshottableSize(Long.MAX_VALUE));
        registry.getOrCreateSnapshot(0);
        assertSame(E_1B, table.snapshottableAddOrReplace(E_1A));
        assertSame(E_1B, table.snapshottableGet(E_1A, 0));
        assertSame(E_1A, table.snapshottableGet(E_1A, Long.MAX_VALUE));
        assertNull(table.snapshottableAddOrReplace(E_2A));
        assertNull(table.snapshottableAddOrReplace(E_3A));
        assertEquals(3, table.snapshottableSize(Long.MAX_VALUE));
        assertEquals(1, table.snapshottableSize(0));
        registry.getOrCreateSnapshot(1);
        assertEquals(E_1A, table.snapshottableRemove(E_1B));
        assertEquals(E_2A, table.snapshottableRemove(E_2A));
        assertEquals(E_3A, table.snapshottableRemove(E_3A));
        assertEquals(0, table.snapshottableSize(Long.MAX_VALUE));
        assertEquals(1, table.snapshottableSize(0));
        assertEquals(3, table.snapshottableSize(1));
        registry.deleteSnapshot(0);
        assertEquals("No in-memory snapshot for epoch 0. Snapshot epochs are: 1",
            assertThrows(RuntimeException.class, () ->
                table.snapshottableSize(0)).getMessage());
        registry.deleteSnapshot(1);
        assertEquals(0, table.snapshottableSize(Long.MAX_VALUE));
    }
The class of test elements.

This class is intended to help test how the table handles distinct objects which
are equal to each other.  Therefore, for the purpose of hashing and equality, we
only check i here, and ignore j.
server-common/src/test/java/org/apache/kafka/timeline/SnapshottableHashTableTest.java