Skip to content

Commit 0fd5ee7

Browse files
Migrate to new logging API
1 parent 2c27cba commit 0fd5ee7

File tree

9 files changed

+32
-33
lines changed

9 files changed

+32
-33
lines changed

datastore/src/main/java/io/spine/server/storage/datastore/DatastoreWrapper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public Entity read(Key key) {
270270
* @see DatastoreReader#run(Query)
271271
*/
272272
public DsQueryIterator read(StructuredQuery<Entity> query) {
273-
Namespace namespace = getNamespace();
273+
Namespace namespace = currentNamespace();
274274
StructuredQuery<Entity> queryWithNamespace =
275275
query.toBuilder()
276276
.setNamespace(namespace.getValue())
@@ -377,7 +377,7 @@ public void delete(Key... keys) {
377377
* kind (a.k.a. type, table, etc.) of the records to delete
378378
*/
379379
void dropTable(String table) {
380-
Namespace namespace = getNamespace();
380+
Namespace namespace = currentNamespace();
381381
StructuredQuery<Entity> query =
382382
Query.newEntityQueryBuilder()
383383
.setNamespace(namespace.getValue())
@@ -497,7 +497,7 @@ public KeyFactory keyFactory(Kind kind) {
497497
if (keyFactory == null) {
498498
keyFactory = initKeyFactory(kind);
499499
}
500-
Namespace namespace = getNamespace();
500+
Namespace namespace = currentNamespace();
501501
keyFactory.setNamespace(namespace.getValue());
502502

503503
return keyFactory;
@@ -536,8 +536,8 @@ private KeyFactory initKeyFactory(Kind kind) {
536536
*/
537537
private Iterator<Entity> readBulk(List<Key> keys) {
538538
int pageCount = keys.size() / MAX_KEYS_PER_READ_REQUEST + 1;
539-
log().debug("Reading a big bulk of entities synchronously. The data is read as {} pages.",
540-
pageCount);
539+
_debug().log("Reading a big bulk of entities synchronously." +
540+
" The data is read as %d pages.", pageCount);
541541
int lowerBound = 0;
542542
int higherBound = MAX_KEYS_PER_READ_REQUEST;
543543
int keysLeft = keys.size();
@@ -567,9 +567,9 @@ private void writeBulk(Entity[] entities) {
567567
}
568568
}
569569

570-
private Namespace getNamespace() {
570+
private Namespace currentNamespace() {
571571
Namespace namespace = namespaceSupplier.get();
572-
log().debug("Using namespace \"{}\".", namespace.getValue());
572+
_debug().log("Using namespace `%s`.", namespace);
573573
return namespace;
574574
}
575575

datastore/src/main/java/io/spine/server/storage/datastore/tenant/Namespace.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ enum ConverterType {
295295
*/
296296
SINGLE_CUSTOM(NamespaceConverters.forCustomNamespace());
297297

298-
// This enum isn't intended to be serialized.
299-
@SuppressWarnings("NonSerializableFieldInSerializableClass")
300298
private final NamespaceConverter namespaceConverter;
301299

302300
static ConverterType forTenantId(TenantId tenantId) {

datastore/src/main/java/io/spine/server/storage/datastore/tenant/NamespaceIndex.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ final class NamespaceIndex implements TenantIndex {
5050
private static final Kind NAMESPACE_KIND = Kind.ofNamespace();
5151

5252
private final Set<Namespace> cache = new HashSet<>();
53-
5453
private final Object lock = new Object();
5554
private final NamespaceQuery namespaceQuery;
56-
5755
private final NsConverterFactory converterFactory;
58-
5956
private final boolean multitenant;
6057

58+
private boolean registered;
59+
6160
NamespaceIndex(Datastore datastore, boolean multitenant, NsConverterFactory converterFactory) {
6261
this(new DefaultNamespaceQuery(datastore),
6362
multitenant,
@@ -66,7 +65,8 @@ final class NamespaceIndex implements TenantIndex {
6665
}
6766

6867
NamespaceIndex(NamespaceQuery namespaceQuery,
69-
boolean multitenant, NsConverterFactory converterFactory) {
68+
boolean multitenant,
69+
NsConverterFactory converterFactory) {
7070
this.namespaceQuery = checkNotNull(namespaceQuery);
7171
this.converterFactory = converterFactory;
7272
this.multitenant = multitenant;
@@ -75,9 +75,13 @@ final class NamespaceIndex implements TenantIndex {
7575
@Override
7676
public void registerWith(BoundedContext context) {
7777
checkNotNull(context);
78+
registered = true;
79+
// Do nothing more, as this implementation does not rely on any `BoundedContext` properties.
80+
}
7881

79-
// Do nothing more, as this implementation does not rely on any {@code BoundedContext}
80-
// properties.
82+
@Override
83+
public boolean isRegistered() {
84+
return registered;
8185
}
8286

8387
/**

datastore/src/test/java/io/spine/server/storage/datastore/BigDataTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void testBigDataOperations(RecordStorage<I> storage) {
130130
readMillisLimit,
131131
readTime));
132132
}
133-
log().debug("Reading took {} millis.", readTime);
133+
_debug().log("Reading took %s millis.", readTime);
134134

135135
assertEquals(records.size(), size(readRecords), "Unexpected records count read.");
136136
}

datastore/src/test/java/io/spine/server/storage/datastore/DsAggregateStorageTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ void testLoadHistoryAfterSnapshotTriggerChange() {
254254
for (int i = 0; i < tasksCount; i++) {
255255
AggAddTask command = addTask(id);
256256
CommandEnvelope envelope = CommandEnvelope.of(factory.createCommand(command));
257-
ProjectId target = repository.dispatch(envelope);
258-
assertEquals(id, target);
257+
repository.dispatch(envelope);
259258
}
260259

261260
int minimalSnapshotTrigger = 1;

datastore/src/test/java/io/spine/server/storage/datastore/TestDatastoreStorageFactory.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@
2222

2323
import com.google.cloud.datastore.Datastore;
2424
import com.google.cloud.datastore.DatastoreOptions;
25+
import com.google.common.flogger.FluentLogger;
2526
import io.spine.annotation.Internal;
26-
import io.spine.logging.Logging;
2727
import io.spine.server.storage.datastore.given.TestDatastores;
2828
import io.spine.server.storage.datastore.type.DatastoreTypeRegistryFactory;
2929
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
30-
import org.slf4j.Logger;
31-
32-
import static java.lang.String.format;
3330

3431
/**
3532
* Creates storages based on the local Google {@link Datastore}.
3633
*/
3734
public class TestDatastoreStorageFactory extends DatastoreStorageFactory {
3835

36+
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
3937
private static @MonotonicNonNull TestDatastoreStorageFactory instance = null;
4038

4139
/**
@@ -53,7 +51,9 @@ public static synchronized TestDatastoreStorageFactory defaultInstance() {
5351
}
5452
return instance;
5553
} catch (Throwable e) {
56-
log().error("Failed to initialize local datastore factory", e);
54+
logger.atSevere()
55+
.withCause(e)
56+
.log("Failed to initialize local datastore factory.");
5757
throw new IllegalStateException(e);
5858
}
5959
}
@@ -111,13 +111,11 @@ public void clear() {
111111
try {
112112
datastore.dropAllTables();
113113
} catch (Throwable e) {
114-
log().error(format("Unable to drop tables in Datastore %s", datastore), e);
114+
logger.atSevere()
115+
.withCause(e)
116+
.log("Unable to drop tables in Datastore `%s`.", datastore);
115117
throw new IllegalStateException(e);
116118
}
117119
}
118120
}
119-
120-
private static Logger log() {
121-
return Logging.get(TestDatastoreStorageFactory.class);
122-
}
123121
}

datastore/src/test/java/io/spine/server/storage/datastore/TestDatastoreWrapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ private void dropTableConsistently(String table) {
141141
@SuppressWarnings("BusyWait") // allow Datastore to become consistent before reading.
142142
private void waitForConsistency() {
143143
if (!waitForConsistency) {
144-
log().debug("Wait for consistency is not required.");
144+
_debug().log("Wait for consistency is not required.");
145145
return;
146146
}
147-
log().debug("Waiting for data consistency to establish.");
147+
_debug().log("Waiting for data consistency to establish.");
148148

149149
for (int awaitCycle = 0; awaitCycle < CONSISTENCY_AWAIT_ITERATIONS; awaitCycle++) {
150150
try {
@@ -159,7 +159,7 @@ private void waitForConsistency() {
159159
* Deletes all records from the datastore.
160160
*/
161161
public void dropAllTables() {
162-
log().debug("Dropping all tables");
162+
_debug().log("Dropping all tables...");
163163
for (String kind : kindsCache) {
164164
dropTable(kind);
165165
}

datastore/src/test/java/io/spine/server/storage/datastore/given/TestDatastores.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private Ci() {
118118
ServiceAccountCredentials credentials = fromStream(bufferedStream);
119119
builder().setCredentials(credentials);
120120
} catch (@SuppressWarnings("OverlyBroadCatchBlock") IOException e) {
121-
log().warn("Cannot find the credentials file {}.", CREDENTIALS_FILE_PATH);
121+
_warn().log("Cannot find the credentials file `%s`.", CREDENTIALS_FILE_PATH);
122122
}
123123
}
124124
}

0 commit comments

Comments
 (0)