Search in sources :

Example 1 with OverflowSequenceSupplier

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OverflowSequenceSupplier in project atlasdb by palantir.

the class OverflowSequenceSupplierTest method shouldGetConsecutiveOverflowIdsFromSameSupplier.

@Test
public void shouldGetConsecutiveOverflowIdsFromSameSupplier() throws Exception {
    final ConnectionSupplier conns = mock(ConnectionSupplier.class);
    final SqlConnection sqlConnection = mock(SqlConnection.class);
    when(conns.get()).thenReturn(sqlConnection);
    when(sqlConnection.selectLongUnregisteredQuery(anyString())).thenReturn(1L);
    OverflowSequenceSupplier sequenceSupplier = OverflowSequenceSupplier.create(conns, "a_");
    long firstSequenceId = sequenceSupplier.get();
    long nextSequenceId = sequenceSupplier.get();
    assertThat(nextSequenceId - firstSequenceId, is(1L));
}
Also used : OverflowSequenceSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OverflowSequenceSupplier) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Test(org.junit.Test)

Example 2 with OverflowSequenceSupplier

use of com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OverflowSequenceSupplier in project atlasdb by palantir.

the class OverflowSequenceSupplierTest method shouldSkipValuesReservedByOtherSupplier.

@Test
public void shouldSkipValuesReservedByOtherSupplier() throws Exception {
    final ConnectionSupplier conns = mock(ConnectionSupplier.class);
    final SqlConnection sqlConnection = mock(SqlConnection.class);
    when(conns.get()).thenReturn(sqlConnection);
    when(sqlConnection.selectLongUnregisteredQuery(anyString())).thenReturn(1L, 1001L, 2001L);
    OverflowSequenceSupplier firstSupplier = OverflowSequenceSupplier.create(conns, "a_");
    // gets 1
    firstSupplier.get();
    // gets 1001
    OverflowSequenceSupplier.create(conns, "a_").get();
    // After 1000 gets from the first supplier, we should get to 1000
    long id = 0;
    for (int i = 0; i < 999; i++) {
        id = firstSupplier.get();
    }
    assertThat(id, equalTo(1000L));
    // Should then skip to 2001
    assertThat(firstSupplier.get(), equalTo(2001L));
}
Also used : OverflowSequenceSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OverflowSequenceSupplier) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Test(org.junit.Test)

Aggregations

OverflowSequenceSupplier (com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OverflowSequenceSupplier)2 SqlConnection (com.palantir.nexus.db.sql.SqlConnection)2 Test (org.junit.Test)2