Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.stream.Collectors;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -326,6 +327,14 @@ public void setUp() {
createCiphertextTables(client);
}

@AfterTest
public void tearDownDDBLocal() {
if (client != null) {
client.shutdown();
client = null;
}
}

@Test(dataProvider = "getDecryptTestVectors")
public void decryptTestVector(Scenario scenario) throws IOException {
client = DynamoDBEmbedded.create().amazonDynamoDB();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import java.util.Map;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

Expand All @@ -47,30 +50,48 @@ public class CachingMostRecentProviderTests {
private static final DynamoDBEncryptor ENCRYPTOR =
DynamoDBEncryptor.getInstance(BASE_PROVIDER);

private AmazonDynamoDB client;
private Map<String, Integer> methodCalls;
private static AmazonDynamoDB rawClient;
private static AmazonDynamoDB instrumentedClient;
private static Map<String, Integer> methodCalls;
private ProviderStore store;
private EncryptionContext ctx;

// DDB Local client is created once per class since DynamoDBEmbedded.create() is expensive.
// Table is created/deleted per method to ensure test isolation, as tests assert
// exact DynamoDB call counts and expect a clean table with no leftover data.
@BeforeClass
public static void setupClient() {
methodCalls = new HashMap<String, Integer>();
rawClient = DynamoDBEmbedded.create().amazonDynamoDB();
instrumentedClient =
instrument(rawClient, AmazonDynamoDB.class, methodCalls);
}

@AfterClass
public static void tearDownDDBLocal() {
if (rawClient != null) {
rawClient.shutdown();
rawClient = null;
}
}

@BeforeMethod
public void setup() {
methodCalls = new HashMap<String, Integer>();
client =
instrument(
DynamoDBEmbedded.create().amazonDynamoDB(),
AmazonDynamoDB.class,
methodCalls
);
MetaStore.createTable(
client,
instrumentedClient,
TABLE_NAME,
new ProvisionedThroughput(1L, 1L)
);
store = new MetaStore(client, TABLE_NAME, ENCRYPTOR);
store = new MetaStore(instrumentedClient, TABLE_NAME, ENCRYPTOR);
ctx = new EncryptionContext.Builder().build();
methodCalls.clear();
}

@AfterMethod
public void tearDown() {
rawClient.deleteTable(TABLE_NAME);
}

@Test
public void testConstructors() {
final CachingMostRecentProvider prov = new CachingMostRecentProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.testng.annotations.AfterClass;

public class DynamoDBTestBase {

Expand All @@ -30,6 +31,14 @@ public static void setUpTestBase() {
dynamo = DynamoDBEmbedded.create().amazonDynamoDB();
}

@AfterClass
public static void tearDownDDBLocal() {
if (dynamo != null) {
dynamo.shutdown();
dynamo = null;
}
}

public static AmazonDynamoDB getClient() {
if (dynamo == null) {
setUpTestBase();
Expand Down
Loading