mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
chore(redshift-data): reuse ManualClock in session and idempotency tests (#6901)
This commit is contained in:
1 parent
5a84d08383
commit
de2e5192b2
2 files changed
+6
-54
No files matched your search
+2
-26
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.PersistentStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.testing.ManualClock;
|
||||
import org.h2.Driver;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@@ -22,8 +23,6 @@ import java.sql.Statement;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -540,7 +539,7 @@ class RedshiftDataIdempotencyServiceTest {
|
||||
private final RedshiftDataConnectionFactory factory = mock(RedshiftDataConnectionFactory.class);
|
||||
private final RedshiftDataEventPublisher publisher = mock(RedshiftDataEventPublisher.class);
|
||||
private final RedshiftDataExecutor executor = new RedshiftDataExecutor(2, 16, 1);
|
||||
private final MutableClock clock = new MutableClock();
|
||||
private final ManualClock clock = new ManualClock(Instant.now());
|
||||
private final RedshiftDataStatementStore statements = spy(new RedshiftDataStatementStore(1, clock));
|
||||
private final RedshiftDataIdempotencyStore receipts = spy(new RedshiftDataIdempotencyStore(
|
||||
AccountAwareStorageBackend.inMemory("000000000000"), clock));
|
||||
@@ -581,27 +580,4 @@ class RedshiftDataIdempotencyServiceTest {
|
||||
executor.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MutableClock extends Clock {
|
||||
private Instant now = Instant.now();
|
||||
|
||||
private void advance(Duration duration) {
|
||||
now = now.plus(duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneId getZone() {
|
||||
return ZoneOffset.UTC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clock withZone(ZoneId zone) {
|
||||
return Clock.fixed(now, zone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant instant() {
|
||||
return now;
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-28
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.redshiftdata;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.testing.ManualClock;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
@@ -12,8 +13,6 @@ import java.sql.SQLException;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -189,7 +188,7 @@ class RedshiftDataSessionsTest {
|
||||
|
||||
@Test
|
||||
void idleDeadlineStartsAfterCompletionAndUnspecifiedTimeoutIsRetained() throws Exception {
|
||||
MutableClock clock = new MutableClock();
|
||||
ManualClock clock = new ManualClock(Instant.parse("2026-10-24T00:00:00Z"));
|
||||
try (RedshiftDataSessions sessions = new RedshiftDataSessions(clock)) {
|
||||
Connection connection = mock(Connection.class);
|
||||
RedshiftDataConnectionFactory factory = mock(RedshiftDataConnectionFactory.class);
|
||||
@@ -218,7 +217,7 @@ class RedshiftDataSessionsTest {
|
||||
|
||||
@Test
|
||||
void busySessionsRejectNewWorkAndFailedAdmissionDoesNotExtendIdleTime() throws Exception {
|
||||
MutableClock clock = new MutableClock();
|
||||
ManualClock clock = new ManualClock(Instant.parse("2026-10-24T00:00:00Z"));
|
||||
try (RedshiftDataSessions sessions = new RedshiftDataSessions(clock)) {
|
||||
RedshiftDataConnectionFactory factory = mock(RedshiftDataConnectionFactory.class);
|
||||
when(factory.open(any())).thenReturn(mock(Connection.class));
|
||||
@@ -273,7 +272,7 @@ class RedshiftDataSessionsTest {
|
||||
|
||||
@Test
|
||||
void absoluteDeadlineClosesAnActiveConnectionAndCannotBeExtended() throws Exception {
|
||||
MutableClock clock = new MutableClock();
|
||||
ManualClock clock = new ManualClock(Instant.parse("2026-10-24T00:00:00Z"));
|
||||
try (RedshiftDataSessions sessions = new RedshiftDataSessions(clock)) {
|
||||
Connection connection = mock(Connection.class);
|
||||
RedshiftDataConnectionFactory factory = mock(RedshiftDataConnectionFactory.class);
|
||||
@@ -331,27 +330,4 @@ class RedshiftDataSessionsTest {
|
||||
assertTrue(sessions.snapshots().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MutableClock extends Clock {
|
||||
private Instant now = Instant.parse("2026-10-24T00:00:00Z");
|
||||
|
||||
void advance(Duration duration) {
|
||||
now = now.plus(duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneId getZone() {
|
||||
return ZoneOffset.UTC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clock withZone(ZoneId zone) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant instant() {
|
||||
return now;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user