Search in sources :

Example 16 with SqlConnection

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);
}
Also used : ConnectionSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier) AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) Connection(java.sql.Connection) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Before(org.junit.Before)

Example 17 with SqlConnection

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));
}
Also used : OverflowSequenceSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OverflowSequenceSupplier) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Test(org.junit.Test)

Example 18 with SqlConnection

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));
}
Also used : SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Test(org.junit.Test)

Example 19 with SqlConnection

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));
}
Also used : OverflowSequenceSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OverflowSequenceSupplier) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Test(org.junit.Test)

Example 20 with SqlConnection

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));
}
Also used : AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) Connection(java.sql.Connection) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) AgnosticResultRow(com.palantir.nexus.db.sql.AgnosticResultRow) Before(org.junit.Before)

Aggregations

SqlConnection (com.palantir.nexus.db.sql.SqlConnection)23 Test (org.junit.Test)11 AgnosticResultSet (com.palantir.nexus.db.sql.AgnosticResultSet)6 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 Before (org.junit.Before)3 ConnectionSupplier (com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier)2 OverflowSequenceSupplier (com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OverflowSequenceSupplier)2 PalantirSqlException (com.palantir.exception.PalantirSqlException)2 AgnosticResultRow (com.palantir.nexus.db.sql.AgnosticResultRow)2 ExecutionException (java.util.concurrent.ExecutionException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 TableMappingNotFoundException (com.palantir.atlasdb.keyvalue.impl.TableMappingNotFoundException)1 SqlTimer (com.palantir.nexus.db.monitoring.timer.SqlTimer)1 AgnosticResultSetImpl (com.palantir.nexus.db.sql.AgnosticResultSetImpl)1 ConnectionBackedSqlConnectionImpl (com.palantir.nexus.db.sql.ConnectionBackedSqlConnectionImpl)1 SQL (com.palantir.nexus.db.sql.SQL)1 SqlConnectionHelper (com.palantir.nexus.db.sql.SqlConnectionHelper)1 ArrayList (java.util.ArrayList)1