Skip to content

Commit d41cff1

Browse files
committed
from using boolean to runnerable
1 parent f59ce4d commit d41cff1

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

src/main/java/com/uid2/operator/Main.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -407,35 +407,35 @@ private Future<Void> createStoreVerticles() throws Exception {
407407

408408
if (clientSideTokenGenerate) {
409409
fs.add(createAndDeployRotatingStoreVerticle("site", siteProvider, "site_refresh_ms",
410-
refreshSucceeded -> this.shutdownHandler.handleStoreRefresh("site", refreshSucceeded)));
410+
() -> this.shutdownHandler.handleStoreRefresh("site")));
411411
fs.add(createAndDeployRotatingStoreVerticle("client_side_keypairs", clientSideKeypairProvider, "client_side_keypairs_refresh_ms",
412-
refreshSucceeded -> this.shutdownHandler.handleStoreRefresh("client_side_keypairs", refreshSucceeded)));
412+
() -> this.shutdownHandler.handleStoreRefresh("client_side_keypairs")));
413413
}
414414

415415
if (validateServiceLinks) {
416416
fs.add(createAndDeployRotatingStoreVerticle("service", serviceProvider, "service_refresh_ms",
417-
refreshSucceeded -> this.shutdownHandler.handleStoreRefresh("service", refreshSucceeded)));
417+
() -> this.shutdownHandler.handleStoreRefresh("service")));
418418
fs.add(createAndDeployRotatingStoreVerticle("service_link", serviceLinkProvider, "service_link_refresh_ms",
419-
refreshSucceeded -> this.shutdownHandler.handleStoreRefresh("service_link", refreshSucceeded)));
419+
() -> this.shutdownHandler.handleStoreRefresh("service_link")));
420420
}
421421

422422
if (encryptedCloudFilesEnabled) {
423423
fs.add(createAndDeployRotatingStoreVerticle("cloud_encryption_keys", cloudEncryptionKeyProvider, "cloud_encryption_keys_refresh_ms",
424-
refreshSucceeded -> this.shutdownHandler.handleStoreRefresh("cloud_encryption_keys", refreshSucceeded)));
424+
() -> this.shutdownHandler.handleStoreRefresh("cloud_encryption_keys")));
425425
}
426426

427427
if (useRemoteConfig) {
428428
fs.add(createAndDeployRotatingStoreVerticle("runtime_config", (RuntimeConfigStore) configStore, Const.Config.ConfigScanPeriodMsProp,
429-
refreshSucceeded -> this.shutdownHandler.handleStoreRefresh("runtime_config", refreshSucceeded)));
429+
() -> this.shutdownHandler.handleStoreRefresh("runtime_config")));
430430
}
431431
fs.add(createAndDeployRotatingStoreVerticle("auth", clientKeyProvider, "auth_refresh_ms",
432-
refreshSucceeded -> this.shutdownHandler.handleStoreRefresh("auth", refreshSucceeded)));
433-
fs.add(createAndDeployRotatingStoreVerticle("keyset", keysetProvider, "keyset_refresh_ms",
434-
refreshSucceeded -> this.shutdownHandler.handleStoreRefresh("keyset", refreshSucceeded)));
435-
fs.add(createAndDeployRotatingStoreVerticle("keysetkey", keysetKeyStore, "keysetkey_refresh_ms",
436-
refreshSucceeded -> this.shutdownHandler.handleStoreRefresh("keysetkey", refreshSucceeded)));
437-
fs.add(createAndDeployRotatingStoreVerticle("salt", saltProvider, "salt_refresh_ms",
438-
refreshSucceeded -> this.shutdownHandler.handleStoreRefresh("salt", refreshSucceeded)));
432+
() -> this.shutdownHandler.handleStoreRefresh("auth")));
433+
fs.add(createAndDeployRotatingStoreVerticle("keyset", keysetProvider, "keyset_refresh_ms",
434+
() -> this.shutdownHandler.handleStoreRefresh("keyset")));
435+
fs.add(createAndDeployRotatingStoreVerticle("keysetkey", keysetKeyStore, "keysetkey_refresh_ms",
436+
() -> this.shutdownHandler.handleStoreRefresh("keysetkey")));
437+
fs.add(createAndDeployRotatingStoreVerticle("salt", saltProvider, "salt_refresh_ms",
438+
() -> this.shutdownHandler.handleStoreRefresh("salt")));
439439
fs.add(createAndDeployCloudSyncStoreVerticle("optout", fsOptOut, optOutCloudSync));
440440
CompositeFuture.all(fs).onComplete(ar -> {
441441
if (ar.failed()) promise.fail(new Exception(ar.cause()));
@@ -453,8 +453,8 @@ private Future<String> createAndDeployRotatingStoreVerticle(String name, IMetada
453453
return createAndDeployRotatingStoreVerticle(name, store, storeRefreshConfigMs, null);
454454
}
455455

456-
private Future<String> createAndDeployRotatingStoreVerticle(String name, IMetadataVersionedStore store, String storeRefreshConfigMs, Consumer<Boolean> refreshCallback) {
457-
final int intervalMs = config.getInteger(storeRefreshConfigMs, 10000);
456+
private Future<String> createAndDeployRotatingStoreVerticle(String name, IMetadataVersionedStore store, String storeRefreshConfigMs, Runnable refreshCallback) {
457+
final long intervalMs = config.getInteger(storeRefreshConfigMs, 10000);
458458

459459
RotatingStoreVerticle rotatingStoreVerticle = new RotatingStoreVerticle(name, intervalMs, store, refreshCallback);
460460
return vertx.deployVerticle(rotatingStoreVerticle);

src/main/java/com/uid2/operator/vertx/OperatorShutdownHandler.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ public void handleAttestResponse(Pair<AttestationResponseCode, String> response)
8080
}
8181
}
8282

83-
public void handleStoreRefresh(String storeName, Boolean success) {
84-
if (success) {
85-
lastSuccessfulRefreshTimes.computeIfAbsent(storeName, k -> new AtomicReference<>())
86-
.set(clock.instant());
87-
}
83+
public void handleStoreRefresh(String storeName) {
84+
lastSuccessfulRefreshTimes.computeIfAbsent(storeName, k -> new AtomicReference<>())
85+
.set(clock.instant());
8886
}
8987

9088
public void checkStoreRefreshStaleness() {

src/test/java/com/uid2/operator/OperatorShutdownHandlerTest.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.slf4j.LoggerFactory;
2020
import software.amazon.awssdk.utils.Pair;
2121

22-
import java.security.Permission;
2322
import java.time.Clock;
2423
import java.time.Duration;
2524
import java.time.Instant;
@@ -62,7 +61,6 @@ void shutdownOnAttestFailure(VertxTestContext testContext) {
6261
this.operatorShutdownHandler.handleAttestResponse(Pair.of(AttestationResponseCode.AttestationFailure, "Unauthorized"));
6362
} catch (RuntimeException e) {
6463
verify(shutdownService).Shutdown(1);
65-
String message = logWatcher.list.get(0).getFormattedMessage();
6664
Assertions.assertEquals("core attestation failed with AttestationFailure, shutting down operator, core response: Unauthorized", logWatcher.list.get(0).getFormattedMessage());
6765
testContext.completeNow();
6866
}
@@ -169,7 +167,7 @@ void saltsLogErrorAtInterval(VertxTestContext testContext) {
169167

170168
@Test
171169
void storeRefreshRecordsSuccessTimestamp(VertxTestContext testContext) {
172-
this.operatorShutdownHandler.handleStoreRefresh("test_store", true);
170+
this.operatorShutdownHandler.handleStoreRefresh("test_store");
173171

174172
when(clock.instant()).thenAnswer(i -> Instant.now().plus(11, ChronoUnit.HOURS));
175173
assertDoesNotThrow(() -> {
@@ -188,15 +186,13 @@ void storeRefreshRecordsSuccessTimestamp(VertxTestContext testContext) {
188186

189187
@Test
190188
void storeRefreshFailureDoesNotResetTimestamp(VertxTestContext testContext) {
191-
this.operatorShutdownHandler.handleStoreRefresh("test_store", true);
189+
this.operatorShutdownHandler.handleStoreRefresh("test_store");
192190

193191
when(clock.instant()).thenAnswer(i -> Instant.now().plus(2, ChronoUnit.HOURS));
194192

195-
this.operatorShutdownHandler.handleStoreRefresh("test_store", false);
196-
this.operatorShutdownHandler.handleStoreRefresh("test_store", false);
197-
this.operatorShutdownHandler.handleStoreRefresh("test_store", false);
193+
// Simulate multiple refresh failures by NOT calling handleStoreRefresh
194+
// (failures don't invoke the callback anymore)
198195

199-
200196
when(clock.instant()).thenAnswer(i -> Instant.now().plus(13, ChronoUnit.HOURS));
201197

202198
try {
@@ -213,7 +209,7 @@ void storeRefreshStaleShutdown(VertxTestContext testContext) {
213209
logWatcher.start();
214210
((Logger) LoggerFactory.getLogger(OperatorShutdownHandler.class)).addAppender(logWatcher);
215211

216-
this.operatorShutdownHandler.handleStoreRefresh("test_store", true);
212+
this.operatorShutdownHandler.handleStoreRefresh("test_store");
217213

218214
when(clock.instant()).thenAnswer(i -> Instant.now().plus(12, ChronoUnit.HOURS).plusSeconds(1));
219215

@@ -230,11 +226,11 @@ void storeRefreshStaleShutdown(VertxTestContext testContext) {
230226

231227
@Test
232228
void storeRefreshRecoverBeforeStale(VertxTestContext testContext) {
233-
this.operatorShutdownHandler.handleStoreRefresh("test_store", true);
229+
this.operatorShutdownHandler.handleStoreRefresh("test_store");
234230

235231
when(clock.instant()).thenAnswer(i -> Instant.now().plus(11, ChronoUnit.HOURS));
236232

237-
this.operatorShutdownHandler.handleStoreRefresh("test_store", true);
233+
this.operatorShutdownHandler.handleStoreRefresh("test_store");
238234

239235
when(clock.instant()).thenAnswer(i -> Instant.now().plus(12, ChronoUnit.HOURS));
240236

@@ -252,14 +248,14 @@ void multipleStoresOneStaleTriggers(VertxTestContext testContext) {
252248
((Logger) LoggerFactory.getLogger(OperatorShutdownHandler.class)).addAppender(logWatcher);
253249

254250

255-
this.operatorShutdownHandler.handleStoreRefresh("store1", true);
256-
this.operatorShutdownHandler.handleStoreRefresh("store2", true);
257-
this.operatorShutdownHandler.handleStoreRefresh("store3", true);
251+
this.operatorShutdownHandler.handleStoreRefresh("store1");
252+
this.operatorShutdownHandler.handleStoreRefresh("store2");
253+
this.operatorShutdownHandler.handleStoreRefresh("store3");
258254

259255
when(clock.instant()).thenAnswer(i -> Instant.now().plus(6, ChronoUnit.HOURS));
260256

261-
this.operatorShutdownHandler.handleStoreRefresh("store1", true);
262-
this.operatorShutdownHandler.handleStoreRefresh("store2", true);
257+
this.operatorShutdownHandler.handleStoreRefresh("store1");
258+
this.operatorShutdownHandler.handleStoreRefresh("store2");
263259

264260
when(clock.instant()).thenAnswer(i -> Instant.now().plus(12, ChronoUnit.HOURS).plusSeconds(1));
265261

0 commit comments

Comments
 (0)