use of com.palantir.nexus.db.sql.SqlConnection in project atlasdb by palantir.
the class OracleTableNameUnmapperTest method setup.
@Before
public void setup() {
connectionSupplier = mock(ConnectionSupplier.class);
oracleTableNameUnmapper = new OracleTableNameUnmapper();
SqlConnection sqlConnection = mock(SqlConnection.class);
Connection connection = mock(Connection.class);
when(sqlConnection.getUnderlyingConnection()).thenReturn(connection);
when(connectionSupplier.get()).thenReturn(sqlConnection);
resultSet = mock(AgnosticResultSet.class);
when(sqlConnection.selectResultSetUnregisteredQuery(startsWith("SELECT short_table_name FROM atlasdb_table_names WHERE table_name"), anyObject())).thenReturn(resultSet);
}
use of com.palantir.nexus.db.sql.SqlConnection 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));
}
use of com.palantir.nexus.db.sql.SqlConnection in project atlasdb by palantir.
the class OverflowSequenceSupplierTest method shouldNotGetOverflowIdsWithOverlappingCachesFromDifferentSuppliers.
@Test
public void shouldNotGetOverflowIdsWithOverlappingCachesFromDifferentSuppliers() 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);
long firstSequenceId = OverflowSequenceSupplier.create(conns, "a_").get();
long secondSequenceId = OverflowSequenceSupplier.create(conns, "a_").get();
assertThat(secondSequenceId - firstSequenceId, greaterThanOrEqualTo(1000L));
}
use of com.palantir.nexus.db.sql.SqlConnection 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));
}
use of com.palantir.nexus.db.sql.SqlConnection in project atlasdb by palantir.
the class TableValueStyleCacheTest method setup.
@Before
public void setup() {
SqlConnection mockConnection = mock(SqlConnection.class);
when(connectionSupplier.get()).thenReturn(mockConnection);
AgnosticResultSet resultSet = mock(AgnosticResultSet.class);
when(mockConnection.selectResultSetUnregisteredQuery(startsWith("SELECT table_size FROM"), anyObject())).thenReturn(resultSet);
AgnosticResultRow row = mock(AgnosticResultRow.class);
when(row.getInteger(eq("table_size"))).thenReturn(TableValueStyle.OVERFLOW.getId());
doReturn(ImmutableList.of(row)).when(resultSet).rows();
when(mockConnection.getUnderlyingConnection()).thenReturn(mock(Connection.class));
}
Aggregations