Skip to content

Commit

Permalink
Merge pull request #219 from sushantmimani/java-updates
Browse files Browse the repository at this point in the history
Java: Rename method and variable
  • Loading branch information
nikoo28 authored Jun 8, 2020
2 parents 0ce8ffa + d745493 commit 1352279
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private EnvelopeEncryption<JSONObject> getEnvelopeEncryptionJson(final String pa
}

Partition getPartition(final String partitionId) {
String regionSuffix = metastore.getRegionSuffix();
String regionSuffix = metastore.getKeySuffix();

if (regionSuffix.isEmpty()) {
return new DefaultPartition(partitionId, serviceId, productId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class DynamoDbMetastoreImpl implements Metastore<JSONObject> {

private final DynamoDB client;
private final String tableName;
private final String regionSuffix;
private final String keySuffix;
// Table instance can be cached since thread-safe and no state other than description, which we don't use
private final Table table;

Expand All @@ -53,7 +53,7 @@ public static Builder newBuilder() {
DynamoDbMetastoreImpl(final Builder builder) {
this.client = new DynamoDB(builder.client);
this.tableName = builder.tableName;
this.regionSuffix = builder.regionSuffix;
this.keySuffix = builder.keySuffix;
this.table = client.getTable(tableName);
}

Expand Down Expand Up @@ -139,8 +139,8 @@ public boolean store(final String key, final Instant created, final JSONObject v
}

@Override
public String getRegionSuffix() {
return regionSuffix;
public String getKeySuffix() {
return keySuffix;
}

String getTableName() {
Expand All @@ -153,12 +153,12 @@ DynamoDB getClient() {

public static final class Builder implements BuildStep, EndPointStep, RegionStep {
static final String DEFAULT_TABLE_NAME = "EncryptionKey";
static final String DEFAULT_REGION_SUFFIX = "";
static final String DEFAULT_KEY_SUFFIX = "";

private AmazonDynamoDB client;

private final AmazonDynamoDBClientBuilder standardBuilder = AmazonDynamoDBClientBuilder.standard();
private String regionSuffix = DEFAULT_REGION_SUFFIX;
private String keySuffix = DEFAULT_KEY_SUFFIX;
private String tableName = DEFAULT_TABLE_NAME;

@Override
Expand All @@ -174,8 +174,8 @@ public BuildStep withTableName(final String table) {
}

@Override
public BuildStep withDynamoDbRegionSuffix(final String suffix) {
this.regionSuffix = suffix;
public BuildStep withKeySuffix(final String suffix) {
this.keySuffix = suffix;
return this;
}

Expand Down Expand Up @@ -213,11 +213,11 @@ public interface RegionStep {

public interface BuildStep {
/**
* Specifies whether region suffix should be enabled for DynamoDB
* Specifies whether key suffix should be enabled for DynamoDB
* @param suffix The region to be used as suffix
* @return The current {@code BuildStep} instance.
*/
BuildStep withDynamoDbRegionSuffix(String suffix);
BuildStep withKeySuffix(String suffix);

/**
* Specifies the name of the table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public interface Metastore<V> {
boolean store(String keyId, Instant created, V value);

/**
* Returns the region suffix or "" if region suffix option is disabled
* @return The region suffix
* Returns the key suffix or "" if key suffix option is disabled
* @return The key suffix
*/
default String getRegionSuffix() {
default String getKeySuffix() {
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void testConstructor() {

@Test
void testSessionCacheSetupAndClose() {
when(metastoreMock.getRegionSuffix()).thenReturn("");
when(metastoreMock.getKeySuffix()).thenReturn("");

// Test flows around session cache setup, including cache loader and removal flows (via close)
CryptoPolicy policy = BasicExpiringCryptoPolicy.newBuilder()
Expand Down Expand Up @@ -731,47 +731,47 @@ void testSessionCacheMultiThreadedWithExpirationDifferentSessions() {

@Test
void testGetSessionJson() {
when(metastoreMock.getRegionSuffix()).thenReturn("");
when(metastoreMock.getKeySuffix()).thenReturn("");

Session<?,?> session = sessionFactory.getSessionJson(testPartitionId);
assertNotNull(session);
}

@Test
void testGetSessionBytes() {
when(metastoreMock.getRegionSuffix()).thenReturn("");
when(metastoreMock.getKeySuffix()).thenReturn("");

Session<?,?> session = sessionFactory.getSessionBytes(testPartitionId);
assertNotNull(session);
}

@Test
void testGetSessionJsonAsJson() {
when(metastoreMock.getRegionSuffix()).thenReturn("");
when(metastoreMock.getKeySuffix()).thenReturn("");

Session<?,?> session = sessionFactory.getSessionJsonAsJson(testPartitionId);
assertNotNull(session);
}

@Test
void testGetSessionBytesAsJson() {
when(metastoreMock.getRegionSuffix()).thenReturn("");
when(metastoreMock.getKeySuffix()).thenReturn("");

Session<?,?> session = sessionFactory.getSessionBytesAsJson(testPartitionId);
assertNotNull(session);
}

@Test
void testGetEnvelopeEncryptionBytes() {
when(metastoreMock.getRegionSuffix()).thenReturn("");
when(metastoreMock.getKeySuffix()).thenReturn("");

EnvelopeEncryption<?> envelopeEncryption = sessionFactory.getEnvelopeEncryptionBytes(testPartitionId);
assertNotNull(envelopeEncryption);
}

@Test
void testGetPartitionWithPartitionId() {
when(metastoreMock.getRegionSuffix()).thenReturn("");
when(metastoreMock.getKeySuffix()).thenReturn("");

Partition partition =
sessionFactory.getPartition(testPartitionId);
Expand All @@ -782,7 +782,7 @@ void testGetPartitionWithPartitionId() {

@Test
void testGetPartitionWithSuffixedPartition() {
when(metastoreMock.getRegionSuffix()).thenReturn(testRegionSuffix);
when(metastoreMock.getKeySuffix()).thenReturn(testRegionSuffix);

Partition partition =
sessionFactory.getPartition(testPartitionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,24 +242,26 @@ void testBuilderPathWithEndPointConfiguration() {
@Test
void testBuilderPathWithRegionSuffix() {
DynamoDbMetastoreImpl dynamoDbMetastore = DynamoDbMetastoreImpl.newBuilder()
.withDynamoDbRegionSuffix("us-west-2")
.withKeySuffix("us-west-2")
.build();

assertEquals("", dynamoDbMetastoreImpl.getRegionSuffix());
assertEquals("us-west-2", dynamoDbMetastore.getRegionSuffix());
assertEquals("", dynamoDbMetastoreImpl.getKeySuffix());
assertEquals("us-west-2", dynamoDbMetastore.getKeySuffix());
}

@Test
void testBuilderPathWithTableName() {
String tableName = "DummyTable";

// Use AWS SDK to create client
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2"))
.build();
DynamoDB dynamoDBclient = new DynamoDB(client);

createTableSchema(dynamoDBclient, tableName);

// Put the object in DummyTable
Table table = dynamoDBclient.getTable(tableName);
Item item = new Item()
.withPrimaryKey(
Expand All @@ -268,12 +270,15 @@ void testBuilderPathWithTableName() {
.withMap(ATTRIBUTE_KEY_RECORD, keyRecord);
table.putItem(item);

// Create a metastore object using the withTableName step
DynamoDbMetastoreImpl dynamoDbMetastore = DynamoDbMetastoreImpl.newBuilder()
.withEndPointConfiguration("http://localhost:8000", "us-west-2")
.withTableName(tableName)
.build();
Optional<JSONObject> actualJsonObject = dynamoDbMetastore.load(TEST_KEY, instant);

// Verify that we were able to load and successfully decrypt the item from the
//metastore object created withTableName
assertTrue(actualJsonObject.isPresent());
assertEquals(keyRecord, actualJsonObject.get().toMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,6 @@ void testPrimaryBuilderPath() {
@Test
void testGetRegionSuffixShouldReturnEmpty() {

assertEquals("", jdbcMetastoreImpl.getRegionSuffix());
assertEquals("", jdbcMetastoreImpl.getKeySuffix());
}
}

0 comments on commit 1352279

Please sign in to comment.