Search in sources :

Example 6 with SqlConnection

use of com.palantir.nexus.db.sql.SqlConnection in project atlasdb by palantir.

the class PostgresDdlTableTest method shouldNotCompactIfVacuumWasPerformedWithinCompactInterval.

@Test
public void shouldNotCompactIfVacuumWasPerformedWithinCompactInterval() {
    SqlConnection sqlConnection = setUpSqlConnection(NOW_MILLIS - COMPACT_INTERVAL_MILLIS / SMALL_POSITIVE_FACTOR, NOW_MILLIS);
    assertThatVacuumWasNotPerformed(sqlConnection);
}
Also used : SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Test(org.junit.Test)

Example 7 with SqlConnection

use of com.palantir.nexus.db.sql.SqlConnection in project atlasdb by palantir.

the class PostgresDdlTableTest method setUpSqlConnection.

private SqlConnection setUpSqlConnection(Long lastVacuumTimestamp, Long currentTimestamp) {
    SqlConnection sqlConnection = mock(SqlConnection.class);
    when(connectionSupplier.get()).thenReturn(sqlConnection);
    List<List<Object>> selectResults = new ArrayList<>();
    selectResults.add(Arrays.asList(new Object[] { lastVacuumTimestamp, currentTimestamp }));
    Mockito.when(sqlConnection.selectResultSetUnregisteredQuery(startsWith("SELECT FLOOR"), any())).thenReturn(new AgnosticResultSetImpl(selectResults, DBType.POSTGRESQL, // upper-case and lower-case, as postgres allows the query to have either of them.
    new ImmutableMap.Builder<String, Integer>().put("last", 0).put("LAST", 0).put("current", 1).put("CURRENT", 1).build()));
    return sqlConnection;
}
Also used : ArrayList(java.util.ArrayList) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableMap(com.google.common.collect.ImmutableMap) AgnosticResultSetImpl(com.palantir.nexus.db.sql.AgnosticResultSetImpl)

Example 8 with SqlConnection

use of com.palantir.nexus.db.sql.SqlConnection in project atlasdb by palantir.

the class PostgresDdlTableTest method shouldCompactIfCompactMillisIsSetToZero.

@Test
public void shouldCompactIfCompactMillisIsSetToZero() throws Exception {
    postgresDdlTable = new PostgresDdlTable(TEST_TABLE, connectionSupplier, ImmutablePostgresDdlConfig.builder().compactInterval(HumanReadableDuration.valueOf("0 ms")).build());
    SqlConnection sqlConnection = setUpSqlConnection(NOW_MILLIS - SMALL_POSITIVE_FACTOR, NOW_MILLIS);
    assertThatVacuumWasPerformed(sqlConnection, false);
    verify(sqlConnection, never()).selectResultSetUnregisteredQuery(startsWith("SELECT FLOOR"), any());
}
Also used : SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Test(org.junit.Test)

Example 9 with SqlConnection

use of com.palantir.nexus.db.sql.SqlConnection in project atlasdb by palantir.

the class PostgresDdlTableTest method shouldCompactIfVacuumWasPerformedBeforeCompactInterval.

@Test
public void shouldCompactIfVacuumWasPerformedBeforeCompactInterval() throws Exception {
    SqlConnection sqlConnection = setUpSqlConnection(NOW_MILLIS - COMPACT_INTERVAL_MILLIS * SMALL_POSITIVE_FACTOR, NOW_MILLIS);
    assertThatVacuumWasPerformed(sqlConnection);
}
Also used : SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Test(org.junit.Test)

Example 10 with SqlConnection

use of com.palantir.nexus.db.sql.SqlConnection in project atlasdb by palantir.

the class PostgresDdlTableTest method shouldNotCompactIfVacuumTimestampExceedsNowTimestampByLessThanCompactInterval.

@Test
public void shouldNotCompactIfVacuumTimestampExceedsNowTimestampByLessThanCompactInterval() {
    SqlConnection sqlConnection = setUpSqlConnection(NOW_MILLIS + COMPACT_INTERVAL_MILLIS / SMALL_POSITIVE_FACTOR, NOW_MILLIS);
    assertThatVacuumWasNotPerformed(sqlConnection);
}
Also used : SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Test(org.junit.Test)

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