diff --git a/atlasdb-cassandra-integration-tests/src/test/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraKeyValueServiceIntegrationTest.java b/atlasdb-cassandra-integration-tests/src/test/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraKeyValueServiceIntegrationTest.java index 1978297a9be..d3cc1771271 100644 --- a/atlasdb-cassandra-integration-tests/src/test/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraKeyValueServiceIntegrationTest.java +++ b/atlasdb-cassandra-integration-tests/src/test/java/com/palantir/atlasdb/keyvalue/cassandra/CassandraKeyValueServiceIntegrationTest.java @@ -34,16 +34,12 @@ import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.stream.Collectors; import org.apache.cassandra.thrift.CfDef; import org.apache.cassandra.thrift.Column; import org.apache.cassandra.thrift.CqlRow; import org.apache.thrift.TException; -import org.junit.After; -import org.junit.Before; import org.junit.ClassRule; import org.junit.Ignore; import org.junit.Test; @@ -76,8 +72,6 @@ public class CassandraKeyValueServiceIntegrationTest extends AbstractKeyValueSer public static final Containers CONTAINERS = new Containers(CassandraKeyValueServiceIntegrationTest.class) .with(new CassandraContainer()); - private KeyValueService keyValueService; - private ExecutorService executorService; private final Logger logger = mock(Logger.class); private TableReference testTable = TableReference.createFromFullyQualifiedName("ns.never_seen"); @@ -97,17 +91,6 @@ public class CassandraKeyValueServiceIntegrationTest extends AbstractKeyValueSer } }.toTableMetadata().persistToBytes(); - @Before - public void setupKvs() { - keyValueService = getKeyValueService(); - executorService = Executors.newFixedThreadPool(4); - } - - @After - public void cleanUp() { - executorService.shutdown(); - } - @Override protected KeyValueService getKeyValueService() { return CassandraKeyValueService.create( diff --git a/atlasdb-jdbc-tests/src/test/java/com/palantir/atlasdb/jdbc/JdbcKeyValueSharedTest.java b/atlasdb-jdbc-tests/src/test/java/com/palantir/atlasdb/jdbc/JdbcKeyValueSharedTest.java index 9e5b0d37169..2c1c3fbca09 100644 --- a/atlasdb-jdbc-tests/src/test/java/com/palantir/atlasdb/jdbc/JdbcKeyValueSharedTest.java +++ b/atlasdb-jdbc-tests/src/test/java/com/palantir/atlasdb/jdbc/JdbcKeyValueSharedTest.java @@ -17,34 +17,15 @@ import com.palantir.atlasdb.keyvalue.api.KeyValueService; import com.palantir.atlasdb.keyvalue.impl.AbstractKeyValueServiceTest; -import com.palantir.atlasdb.keyvalue.jdbc.JdbcKeyValueService; public class JdbcKeyValueSharedTest extends AbstractKeyValueServiceTest { - private JdbcKeyValueService db = null; - - @Override - public void setUp() throws Exception { - db = JdbcTests.createEmptyKvs(); - super.setUp(); + protected KeyValueService getKeyValueService() { + return JdbcTests.createEmptyKvs(); } @Override protected boolean reverseRangesSupported() { return true; } - - @Override - protected KeyValueService getKeyValueService() { - return db; - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - if (db != null) { - db.close(); - db = null; - } - } } diff --git a/atlasdb-jdbc-tests/src/test/java/com/palantir/atlasdb/jdbc/JdbcTransactionTest.java b/atlasdb-jdbc-tests/src/test/java/com/palantir/atlasdb/jdbc/JdbcTransactionTest.java index 30703720cf7..bb140b4e9f4 100644 --- a/atlasdb-jdbc-tests/src/test/java/com/palantir/atlasdb/jdbc/JdbcTransactionTest.java +++ b/atlasdb-jdbc-tests/src/test/java/com/palantir/atlasdb/jdbc/JdbcTransactionTest.java @@ -16,34 +16,16 @@ package com.palantir.atlasdb.jdbc; import com.palantir.atlasdb.keyvalue.api.KeyValueService; -import com.palantir.atlasdb.keyvalue.jdbc.JdbcKeyValueService; import com.palantir.atlasdb.transaction.impl.AbstractTransactionTest; public class JdbcTransactionTest extends AbstractTransactionTest { - private JdbcKeyValueService db = null; - - @Override - public void setUp() throws Exception { - db = JdbcTests.createEmptyKvs(); - super.setUp(); - } - @Override protected KeyValueService getKeyValueService() { - return db; + return JdbcTests.createEmptyKvs(); } @Override protected boolean supportsReverse() { return true; } - - @Override - public void tearDown() { - super.tearDown(); - if (db != null) { - db.close(); - db = null; - } - } } diff --git a/atlasdb-rocksdb-tests/src/test/java/com/palantir/atlasdb/keyvalue/rocksdb/impl/RocksDbKeyValueSharedTest.java b/atlasdb-rocksdb-tests/src/test/java/com/palantir/atlasdb/keyvalue/rocksdb/impl/RocksDbKeyValueSharedTest.java index 9834a70f3dd..10e40a1f301 100644 --- a/atlasdb-rocksdb-tests/src/test/java/com/palantir/atlasdb/keyvalue/rocksdb/impl/RocksDbKeyValueSharedTest.java +++ b/atlasdb-rocksdb-tests/src/test/java/com/palantir/atlasdb/keyvalue/rocksdb/impl/RocksDbKeyValueSharedTest.java @@ -15,40 +15,36 @@ */ package com.palantir.atlasdb.keyvalue.rocksdb.impl; +import java.util.Set; +import java.util.stream.Collectors; + import com.palantir.atlasdb.keyvalue.api.KeyValueService; import com.palantir.atlasdb.keyvalue.api.TableReference; import com.palantir.atlasdb.keyvalue.impl.AbstractKeyValueServiceTest; public class RocksDbKeyValueSharedTest extends AbstractKeyValueServiceTest { - private RocksDbKeyValueService db = null; - - @Override - public void setUp() throws Exception { - db = RocksDbKeyValueService.create("testdb"); - for (TableReference table : db.getAllTableNames()) { - if (!table.getQualifiedName().equals("default") && !table.getQualifiedName().equals("_metadata")) { - db.dropTable(table); - } - } - super.setUp(); - } - @Override protected boolean reverseRangesSupported() { return false; } - @Override - protected KeyValueService getKeyValueService() { - return db; - } + @Override + protected KeyValueService getKeyValueService() { + KeyValueService db = RocksDbKeyValueService.create("testdb"); + cleanup(db); + return db; + } @Override - public void tearDown() throws Exception { - super.tearDown(); - if (db != null) { - db.close(); - db = null; - } + public void tearDown() { + cleanup(keyValueService); + } + + private static void cleanup(KeyValueService db) { + Set nonMetadataTables = db.getAllTableNames().stream() + .filter(tableRef -> !tableRef.getNamespace().getName().equals("default") + || !tableRef.getTablename().equals("_metadata")) + .collect(Collectors.toSet()); + db.dropTables(nonMetadataTables); } } diff --git a/atlasdb-rocksdb-tests/src/test/java/com/palantir/atlasdb/keyvalue/rocksdb/impl/RocksTransactionTest.java b/atlasdb-rocksdb-tests/src/test/java/com/palantir/atlasdb/keyvalue/rocksdb/impl/RocksTransactionTest.java index b7c25ec4444..451999d05be 100644 --- a/atlasdb-rocksdb-tests/src/test/java/com/palantir/atlasdb/keyvalue/rocksdb/impl/RocksTransactionTest.java +++ b/atlasdb-rocksdb-tests/src/test/java/com/palantir/atlasdb/keyvalue/rocksdb/impl/RocksTransactionTest.java @@ -15,26 +15,26 @@ */ package com.palantir.atlasdb.keyvalue.rocksdb.impl; +import java.util.Set; +import java.util.stream.Collectors; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.palantir.atlasdb.AtlasDbConstants; import com.palantir.atlasdb.keyvalue.api.KeyValueService; import com.palantir.atlasdb.keyvalue.api.TableReference; import com.palantir.atlasdb.transaction.impl.AbstractTransactionTest; +import com.palantir.atlasdb.transaction.impl.TransactionConstants; public class RocksTransactionTest extends AbstractTransactionTest { - private RocksDbKeyValueService db = null; - - @Override - public void setUp() throws Exception { - db = RocksDbKeyValueService.create("testdb"); - for (TableReference tableRef : db.getAllTableNames()) { - if (!tableRef.getNamespace().getName().equals("default") && !tableRef.getTablename().equals("_metadata")) { - db.dropTable(tableRef); - } - } - super.setUp(); - } - @Override protected KeyValueService getKeyValueService() { + KeyValueService db = RocksDbKeyValueService.create("testdb"); + Set nonMetadataTables = db.getAllTableNames().stream() + .filter(tableRef -> !tableRef.getNamespace().getName().equals("default") + || !tableRef.getTablename().equals("_metadata")) + .collect(Collectors.toSet()); + db.dropTables(nonMetadataTables); return db; } @@ -45,10 +45,11 @@ protected boolean supportsReverse() { @Override public void tearDown() { - super.tearDown(); - if (db != null) { - db.close(); - db = null; - } + // This is implemented as a drop/create instead of a truncate() because of a actual issues + // in the RocksDB KVS + keyValueService.dropTables(ImmutableSet.of(TEST_TABLE, TransactionConstants.TRANSACTION_TABLE)); + keyValueService.createTables(ImmutableMap.of( + TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA, + TransactionConstants.TRANSACTION_TABLE, TransactionConstants.TRANSACTION_TABLE_METADATA.persistToBytes())); } } diff --git a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/keyvalue/impl/AbstractKeyValueServiceTest.java b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/keyvalue/impl/AbstractKeyValueServiceTest.java index e4a38a3578e..fcaac6fd9ec 100644 --- a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/keyvalue/impl/AbstractKeyValueServiceTest.java +++ b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/keyvalue/impl/AbstractKeyValueServiceTest.java @@ -35,6 +35,7 @@ import org.apache.commons.lang.ArrayUtils; import org.junit.After; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -87,12 +88,10 @@ public abstract class AbstractKeyValueServiceTest { protected static final byte[] value0_t1 = "value1_t1".getBytes(); protected static final byte[] value0_t5 = "value5_t5".getBytes(); - protected static final byte[] metadata0 = "metadata0".getBytes(); - protected static final long TEST_TIMESTAMP = 1000000l; private static final long MAX_TIMESTAMP = Long.MAX_VALUE; - protected KeyValueService keyValueService; + protected static KeyValueService keyValueService = null; protected boolean reverseRangesSupported() { return true; @@ -100,14 +99,22 @@ protected boolean reverseRangesSupported() { @Before public void setUp() throws Exception { - keyValueService = getKeyValueService(); + if (keyValueService == null) { + keyValueService = getKeyValueService(); + } keyValueService.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA); } @After public void tearDown() throws Exception { - keyValueService.dropTables(keyValueService.getAllTableNames()); - keyValueService.close(); + keyValueService.truncateTables(ImmutableSet.of(TEST_TABLE)); + } + + @AfterClass + public static void tearDownKvs() { + if (keyValueService != null) { + keyValueService.close(); + } } @Test diff --git a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/AbstractTransactionTest.java b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/AbstractTransactionTest.java index 6290826ae87..2a359f905ee 100644 --- a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/AbstractTransactionTest.java +++ b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/AbstractTransactionTest.java @@ -1170,6 +1170,9 @@ public void testGetRangesPaging() { @Test public void testTableMetadata() { + keyValueService.dropTable(TEST_TABLE); + keyValueService.createTable(TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA); + byte[] metadataForTable = keyValueService.getMetadataForTable(TEST_TABLE); assertTrue(metadataForTable == null || Arrays.equals(AtlasDbConstants.GENERIC_TABLE_METADATA, metadataForTable)); byte[] bytes = new TableMetadata().persistToBytes(); diff --git a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/TransactionTestSetup.java b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/TransactionTestSetup.java index e3e875708e9..efd06b5c453 100644 --- a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/TransactionTestSetup.java +++ b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/TransactionTestSetup.java @@ -51,7 +51,7 @@ public abstract class TransactionTestSetup { protected static LockClient lockClient = null; protected static LockServiceImpl lockService = null; - protected KeyValueService keyValueService; + protected static KeyValueService keyValueService; protected TimestampService timestampService; protected TransactionService transactionService; protected ConflictDetectionManager conflictDetectionManager; @@ -82,12 +82,17 @@ public boolean isStandaloneServer() { @Before public void setUp() throws Exception { - keyValueService = getKeyValueService(); + if (keyValueService == null) { + keyValueService = getKeyValueService(); + + keyValueService.createTables(ImmutableMap.of( + TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA, + TransactionConstants.TRANSACTION_TABLE, TransactionConstants.TRANSACTION_TABLE_METADATA.persistToBytes())); + keyValueService.truncateTables(ImmutableSet.of(TEST_TABLE, TransactionConstants.TRANSACTION_TABLE)); + } + timestampService = new InMemoryTimestampService(); - keyValueService.createTables(ImmutableMap.of( - TEST_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA, - TransactionConstants.TRANSACTION_TABLE, TransactionConstants.TRANSACTION_TABLE_METADATA.persistToBytes())); - keyValueService.truncateTables(ImmutableSet.of(TEST_TABLE, TransactionConstants.TRANSACTION_TABLE)); + transactionService = TransactionServices.createTransactionService(keyValueService); conflictDetectionManager = ConflictDetectionManagers.createDefault(keyValueService); sweepStrategyManager = SweepStrategyManagers.createDefault(keyValueService); @@ -96,8 +101,15 @@ public void setUp() throws Exception { @After public void tearDown() { - keyValueService.dropTables(ImmutableSet.of(TEST_TABLE, TransactionConstants.TRANSACTION_TABLE)); - keyValueService.close(); + keyValueService.truncateTables(ImmutableSet.of(TEST_TABLE, TransactionConstants.TRANSACTION_TABLE)); + } + + @AfterClass + public static void tearDownKvs() { + if (keyValueService != null) { + keyValueService.close(); + keyValueService = null; + } } @AfterClass diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/MemorySerializableTransactionTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/MemorySerializableTransactionTest.java index fc14bcd098b..ff321626c22 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/MemorySerializableTransactionTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/MemorySerializableTransactionTest.java @@ -21,10 +21,8 @@ import com.palantir.common.concurrent.PTExecutors; public class MemorySerializableTransactionTest extends AbstractSerializableTransactionTest { - @Override protected KeyValueService getKeyValueService() { - return new InMemoryKeyValueService(false, PTExecutors.newSingleThreadExecutor(PTExecutors.newNamedThreadFactory(true))); + return new InMemoryKeyValueService(false, PTExecutors.newSingleThreadExecutor(PTExecutors.newNamedThreadFactory(false))); } - } diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/MemoryTransactionTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/MemoryTransactionTest.java index d1a3222a12f..1f7839b6800 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/MemoryTransactionTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/MemoryTransactionTest.java @@ -21,10 +21,8 @@ import com.palantir.common.concurrent.PTExecutors; public class MemoryTransactionTest extends AbstractTransactionTest { - @Override protected KeyValueService getKeyValueService() { - return new InMemoryKeyValueService(false, PTExecutors.newSingleThreadExecutor(PTExecutors.newNamedThreadFactory(true))); + return new InMemoryKeyValueService(false, PTExecutors.newSingleThreadExecutor(PTExecutors.newNamedThreadFactory(false))); } - }