Skip to content

Commit 4f184ad

Browse files
authored
use new logging API introduced in Java SDK 5.10.0 (#18)
1 parent 48ec95a commit 4f184ad

File tree

8 files changed

+58
-30
lines changed

8 files changed

+58
-30
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ To build the library and run all unit tests:
4040
./gradlew test
4141
```
4242

43-
The tests expect you to have DynamoDB running locally. The simplest way to do that is with Docker: `docker run -p 8000:8000 amazon/dynamodb-local`
43+
The tests expect you to have DynamoDB running locally. The simplest way to do that is with Docker:
44+
45+
```shell
46+
docker run -p 8000:8000 amazon/dynamodb-local
47+
```
4448

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
This library provides a DynamoDB-backed persistence mechanism (data store) for the [LaunchDarkly Java SDK](https://github.com/launchdarkly/java-server-sdk), replacing the default in-memory data store.
77

8-
This version of the library requires at least version 5.0.0 of the LaunchDarkly Java SDK, and at least version 2.1 of the AWS SDK for Java. The minimum Java version is 8. For Java SDK 4.x, use the latest 2.x version of this library.
8+
This version of the library requires at least version 5.10.0 of the LaunchDarkly Java SDK, and at least version 2.1 of the AWS SDK for Java. The minimum Java version is 8.
9+
10+
For Java SDK 5.0 through 5.9, use the latest 3.x version of this library. For Java SDK 4.x, use the latest 2.x version.
911

1012
If you need to use Java 7, or if you are already using AWS SDK 1.x for some other purpose, you can use the 1.x releases of this library (which are developed on the "aws-v1" branch of the repository).
1113

build.gradle

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,18 @@ allprojects {
3838
}
3939

4040
ext.versions = [
41-
"sdk": "5.7.0", // the *lowest* version we're compatible with
42-
"dynamodb": "2.10.32",
43-
"slf4j": "1.7.21"
41+
"sdk": "5.10.0", // the *lowest* version we're compatible with
42+
"dynamodb": "2.10.32"
4443
]
4544

4645
ext.libraries = [:]
4746

4847
dependencies {
4948
api "com.launchdarkly:launchdarkly-java-server-sdk:${versions.sdk}"
5049
api "software.amazon.awssdk:dynamodb:${versions.dynamodb}"
51-
api "org.slf4j:slf4j-api:${versions.slf4j}"
5250
testImplementation "org.hamcrest:hamcrest-all:1.3"
5351
testImplementation "junit:junit:4.12"
5452
testImplementation "com.launchdarkly:launchdarkly-java-server-sdk:${versions.sdk}:test" // our unit tests use helper classes from the SDK
55-
testImplementation "ch.qos.logback:logback-classic:1.1.7"
5653
testImplementation "com.google.guava:guava:28.2-jre" // required by SDK tests, not used in this library itself
5754
testImplementation "com.google.code.gson:gson:2.7" // same as above
5855
}

src/main/java/com/launchdarkly/sdk/server/integrations/DynamoDbBigSegmentStoreImpl.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.launchdarkly.sdk.server.interfaces.BigSegmentStoreTypes.createMembershipFromSegmentRefs;
44

5+
import com.launchdarkly.logging.LDLogger;
56
import com.launchdarkly.sdk.server.interfaces.BigSegmentStore;
67
import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreTypes;
78

@@ -19,8 +20,15 @@ public class DynamoDbBigSegmentStoreImpl extends DynamoDbStoreImplBase implement
1920
private final static String METADATA_KEY = "big_segments_metadata";
2021
private final static String SYNC_TIME_ATTR = "synchronizedOn";
2122

22-
DynamoDbBigSegmentStoreImpl(DynamoDbClient client, boolean wasExistingClient, String tableName, String prefix) {
23-
super(client, wasExistingClient, tableName, prefix);
23+
DynamoDbBigSegmentStoreImpl(
24+
DynamoDbClient client,
25+
boolean wasExistingClient,
26+
String tableName,
27+
String prefix,
28+
LDLogger baseLogger
29+
) {
30+
super(client, wasExistingClient, tableName, prefix,
31+
baseLogger.subLogger("BigSegments").subLogger("DynamoDb"));
2432
}
2533

2634
@Override

src/main/java/com/launchdarkly/sdk/server/integrations/DynamoDbDataStoreBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public DynamoDbDataStoreBuilder existingClient(DynamoDbClient existingClient) {
123123
@Override
124124
public PersistentDataStore createPersistentDataStore(ClientContext context) {
125125
DynamoDbClient client = (existingClient != null) ? existingClient : clientBuilder.build();
126-
return new DynamoDbDataStoreImpl(client, existingClient != null, tableName, prefix);
126+
return new DynamoDbDataStoreImpl(client, existingClient != null, tableName, prefix,
127+
context.getBasic().getBaseLogger());
127128
}
128129

129130
/**
@@ -133,7 +134,8 @@ public PersistentDataStore createPersistentDataStore(ClientContext context) {
133134
@Override
134135
public BigSegmentStore createBigSegmentStore(ClientContext context) {
135136
DynamoDbClient client = (existingClient != null) ? existingClient : clientBuilder.build();
136-
return new DynamoDbBigSegmentStoreImpl(client, existingClient != null, tableName, prefix);
137+
return new DynamoDbBigSegmentStoreImpl(client, existingClient != null, tableName, prefix,
138+
context.getBasic().getBaseLogger());
137139
}
138140

139141
@Override

src/main/java/com/launchdarkly/sdk/server/integrations/DynamoDbDataStoreImpl.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.launchdarkly.sdk.server.integrations;
22

3+
import com.launchdarkly.logging.LDLogger;
34
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.DataKind;
45
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.FullDataSet;
56
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.KeyedItems;
67
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.SerializedItemDescriptor;
78
import com.launchdarkly.sdk.server.interfaces.PersistentDataStore;
89

9-
import org.slf4j.Logger;
10-
import org.slf4j.LoggerFactory;
11-
1210
import java.util.AbstractMap;
1311
import java.util.ArrayList;
1412
import java.util.HashSet;
@@ -59,8 +57,6 @@
5957
* </ul>
6058
*/
6159
final class DynamoDbDataStoreImpl extends DynamoDbStoreImplBase implements PersistentDataStore {
62-
private static final Logger logger = LoggerFactory.getLogger("com.launchdarkly.sdk.server.LDClient.DataStore.DynamoDB");
63-
6460
private static final String versionAttribute = "version";
6561
private static final String itemJsonAttribute = "item";
6662
private static final String deletedItemPlaceholder = "null"; // DynamoDB doesn't allow empty strings
@@ -72,8 +68,15 @@ final class DynamoDbDataStoreImpl extends DynamoDbStoreImplBase implements Persi
7268

7369
private Runnable updateHook;
7470

75-
DynamoDbDataStoreImpl(DynamoDbClient client, boolean wasExistingClient, String tableName, String prefix) {
76-
super(client, wasExistingClient, tableName, prefix);
71+
DynamoDbDataStoreImpl(
72+
DynamoDbClient client,
73+
boolean wasExistingClient,
74+
String tableName,
75+
String prefix,
76+
LDLogger baseLogger
77+
) {
78+
super(client, wasExistingClient, tableName, prefix,
79+
baseLogger.subLogger("DataStore").subLogger("DynamoDb"));
7780
}
7881

7982
@Override
@@ -285,7 +288,7 @@ static void batchWriteRequests(DynamoDbClient client, String tableName, List<Wri
285288
}
286289
}
287290

288-
private static boolean checkSizeLimit(Map<String, AttributeValue> item) {
291+
private boolean checkSizeLimit(Map<String, AttributeValue> item) {
289292
// see: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CapacityUnitCalculations.html
290293
int size = 100; // fixed overhead for index data
291294
for (Map.Entry<String, AttributeValue> kv: item.entrySet()) {

src/main/java/com/launchdarkly/sdk/server/integrations/DynamoDbStoreImplBase.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import static com.launchdarkly.sdk.server.integrations.CollectionHelpers.mapOf;
44

5+
import com.launchdarkly.logging.LDLogger;
6+
57
import java.io.Closeable;
68
import java.io.IOException;
79
import java.util.Map;
@@ -18,12 +20,20 @@ abstract class DynamoDbStoreImplBase implements Closeable {
1820
protected final boolean wasExistingClient;
1921
protected final String tableName;
2022
protected final String prefix;
21-
22-
public DynamoDbStoreImplBase(DynamoDbClient client, boolean wasExistingClient, String tableName, String prefix) {
23+
protected final LDLogger logger;
24+
25+
public DynamoDbStoreImplBase(
26+
DynamoDbClient client,
27+
boolean wasExistingClient,
28+
String tableName,
29+
String prefix,
30+
LDLogger logger
31+
) {
2332
this.client = client;
2433
this.wasExistingClient = wasExistingClient;
2534
this.tableName = tableName;
2635
this.prefix = "".equals(prefix) ? null : prefix;
36+
this.logger = logger;
2737
}
2838

2939
protected String prefixedNamespace(String base) {

src/test/java/com/launchdarkly/sdk/server/integrations/DynamoDbDataStoreImplTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import com.google.common.collect.Iterables;
66
import com.google.common.collect.Lists;
77
import com.launchdarkly.sdk.server.DataModel;
8+
import com.launchdarkly.sdk.server.interfaces.ClientContext;
89
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.DataKind;
910
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.FullDataSet;
1011
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.KeyedItems;
1112
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.SerializedItemDescriptor;
1213
import com.launchdarkly.sdk.server.interfaces.PersistentDataStore;
14+
import com.launchdarkly.sdk.server.interfaces.PersistentDataStoreFactory;
1315

1416
import org.junit.BeforeClass;
1517
import org.junit.Test;
@@ -19,6 +21,7 @@
1921
import java.util.List;
2022
import java.util.Map;
2123

24+
import static com.launchdarkly.sdk.server.TestComponents.clientContext;
2225
import static com.launchdarkly.sdk.server.integrations.TestUtils.baseBuilder;
2326
import static com.launchdarkly.sdk.server.integrations.TestUtils.clearEverything;
2427
import static com.launchdarkly.sdk.server.integrations.TestUtils.createTableIfNecessary;
@@ -44,13 +47,8 @@ public static void setUpAll() {
4447
}
4548

4649
@Override
47-
protected DynamoDbDataStoreImpl makeStore() {
48-
return (DynamoDbDataStoreImpl)baseBuilder().createPersistentDataStore(null);
49-
}
50-
51-
@Override
52-
protected DynamoDbDataStoreImpl makeStoreWithPrefix(String prefix) {
53-
return (DynamoDbDataStoreImpl)baseBuilder().prefix(prefix).createPersistentDataStore(null);
50+
protected PersistentDataStoreFactory buildStore(String prefix) {
51+
return baseBuilder().prefix(prefix);
5452
}
5553

5654
@Override
@@ -104,7 +102,7 @@ private void dataStoreSkipsAndLogsTooLargeItemOnInit(
104102
// Initialize the store with this data set. It should not throw an exception, but instead just
105103
// log an error and store all the *other* items-- so the resulting state should be the same as
106104
// makeGoodData().
107-
try (PersistentDataStore store = makeStore()) {
105+
try (PersistentDataStore store = buildStore(null).createPersistentDataStore(makeClientContext())) {
108106
store.init(new FullDataSet<>(dataPlusBadItem));
109107

110108
assertDataSetsEqual(goodData, getAllData(store));
@@ -117,7 +115,7 @@ private void dataStoreSkipsAndLogsTooLargeItemOnUpsert(
117115
FullDataSet<SerializedItemDescriptor> goodData = makeGoodData();
118116

119117
// Initialize the store with valid data.
120-
try (PersistentDataStore store = makeStore()) {
118+
try (PersistentDataStore store = buildStore(null).createPersistentDataStore(makeClientContext())) {
121119
store.init(goodData);
122120

123121
assertDataSetsEqual(goodData, getAllData(store));
@@ -130,6 +128,10 @@ private void dataStoreSkipsAndLogsTooLargeItemOnUpsert(
130128
}
131129
}
132130

131+
private ClientContext makeClientContext() {
132+
return clientContext("", baseConfig().build());
133+
}
134+
133135
private static FullDataSet<SerializedItemDescriptor> makeGoodData() {
134136
return new FullDataSet<SerializedItemDescriptor>(ImmutableList.of(
135137
new SimpleEntry<>(DataModel.FEATURES,

0 commit comments

Comments
 (0)