mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor: read schedules' and pipe sources' Regions with regionOf (#8893)
* refactor: read schedules' and pipe sources' Regions with regionOf
This commit is contained in:
1 parent
466912f939
commit
c0325c5488
9 files changed
+71
-36
No files matched your search
@@ -81,7 +81,8 @@ class PipesKinesisTerminalTest {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
when(config.effectiveBaseUrl()).thenReturn("http://localhost:4566");
|
||||
PipesPoller poller = new PipesPoller(mock(Vertx.class), sqs, kinesis, mock(DynamoDbStreamReader.class),
|
||||
mock(PipesKafkaConsumerManager.class), target, new PipesFilterMatcher(mapper), mapper, config);
|
||||
mock(PipesKafkaConsumerManager.class), target, new PipesFilterMatcher(mapper), mapper, config,
|
||||
new RegionResolver("eu-west-1", "111111111111"));
|
||||
try {
|
||||
for (int i = 0; i < recordCount + 3; i++) {
|
||||
poller.pollKinesis(pipe, "eu-west-1");
|
||||
|
||||
@@ -57,6 +57,7 @@ import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.timeout;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -91,8 +92,12 @@ class PipesPollerTest {
|
||||
}
|
||||
|
||||
private PipesPoller pollerOver(DynamoDbStreamReader streamReader) {
|
||||
return pollerOver(streamReader, new RegionResolver("us-east-1", "000000000000"));
|
||||
}
|
||||
|
||||
private PipesPoller pollerOver(DynamoDbStreamReader streamReader, RegionResolver regionResolver) {
|
||||
return new PipesPoller(vertx, sqsService, kinesisService, streamReader,
|
||||
kafkaConsumerManager, targetInvoker, new PipesFilterMatcher(MAPPER), MAPPER, config);
|
||||
kafkaConsumerManager, targetInvoker, new PipesFilterMatcher(MAPPER), MAPPER, config, regionResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,12 +141,21 @@ class PipesPollerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSourceWithoutAnArnRegionPollsInTheDeploymentDefaultRegion() {
|
||||
when(config.defaultRegion()).thenReturn("cn-north-1");
|
||||
PipesPoller chinaPoller = pollerOver(streams);
|
||||
void aSourceWithoutAnArnRegionPollsInTheDeploymentDefaultRegion() throws Exception {
|
||||
PipesPoller chinaPoller = pollerOver(streams, new RegionResolver("cn-north-1", "000000000000"));
|
||||
Pipe pipe = selfManagedKafkaPipe();
|
||||
pipe.setDesiredState(DesiredState.RUNNING);
|
||||
when(kafkaConsumerManager.poll(pipe)).thenReturn(List.of(kafkaRecord("orders", 0, 42L,
|
||||
"customer-123".getBytes(StandardCharsets.UTF_8),
|
||||
"{\"status\":\"active\"}".getBytes(StandardCharsets.UTF_8))));
|
||||
chinaPoller.startPolling(pipe);
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Handler<Long>> tick = ArgumentCaptor.forClass(Handler.class);
|
||||
verify(vertx).setPeriodic(eq(1000L), tick.capture());
|
||||
|
||||
assertEquals("cn-north-1", chinaPoller.extractRegionFromArn("smk://broker.internal:9092"));
|
||||
assertEquals("eu-west-1", chinaPoller.extractRegionFromArn("arn:aws:sqs:eu-west-1:000000000000:orders"));
|
||||
tick.getValue().handle(1L);
|
||||
|
||||
verify(targetInvoker, timeout(5000)).invoke(eq(pipe), anyString(), eq("cn-north-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.floci.aws.services.scheduler;
|
||||
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.services.scheduler.model.DeadLetterConfig;
|
||||
import io.floci.aws.services.scheduler.model.RetryPolicy;
|
||||
import io.floci.aws.services.scheduler.model.Schedule;
|
||||
@@ -50,7 +51,8 @@ class ScheduleDispatcherTest {
|
||||
when(config.services()).thenReturn(servicesCfg);
|
||||
when(config.baseUrl()).thenReturn("http://localhost:4566");
|
||||
|
||||
dispatcher = new ScheduleDispatcher(schedulerService, invoker, sqsService, config);
|
||||
dispatcher = new ScheduleDispatcher(schedulerService, invoker, sqsService, config,
|
||||
new RegionResolver("us-east-1", "000000000000"));
|
||||
}
|
||||
|
||||
private Schedule newSchedule(String name, String expression, String state) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.ServiceRegistry;
|
||||
import io.floci.aws.services.ecs.EcsService;
|
||||
import io.floci.aws.services.ecs.model.ContainerOverride;
|
||||
@@ -84,13 +85,18 @@ class ScheduleInvokerTest {
|
||||
}
|
||||
|
||||
private ScheduleInvoker invokerWithRedshiftEnabled(boolean redshiftEnabled, boolean redshiftDataEnabled) {
|
||||
return invoker(redshiftEnabled, redshiftDataEnabled, new RegionResolver("us-east-1", "000000000000"));
|
||||
}
|
||||
|
||||
private ScheduleInvoker invoker(boolean redshiftEnabled, boolean redshiftDataEnabled,
|
||||
RegionResolver regionResolver) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(config.baseUrl()).thenReturn("http://localhost:4566");
|
||||
ServiceRegistry serviceRegistry = mock(ServiceRegistry.class);
|
||||
when(serviceRegistry.isServiceEnabled("redshift-data")).thenReturn(redshiftEnabled && redshiftDataEnabled);
|
||||
return new ScheduleInvoker(sqsService, lambdaService, snsService,
|
||||
eventBridgeService, ecsService, stepFunctionsService, redshiftDataService,
|
||||
new ObjectMapper(), config, serviceRegistry);
|
||||
new ObjectMapper(), config, regionResolver, serviceRegistry);
|
||||
}
|
||||
|
||||
/** Delivers one occurrence of a schedule in {@code region} whose target is {@code target}. */
|
||||
@@ -113,11 +119,22 @@ class ScheduleInvokerTest {
|
||||
|
||||
@Test
|
||||
void aScheduleWithoutAnArnLivesInTheDeploymentDefaultRegion() {
|
||||
ScheduleInvoker chinaInvoker = invoker(true, true, new RegionResolver("cn-north-1", "000000000000"));
|
||||
Target target = new Target();
|
||||
target.setArn("arn:aws:scheduler:::aws-sdk:sqs:sendMessage");
|
||||
target.setRoleArn("arn:aws:iam::000000000000:role/x");
|
||||
target.setInput("{\"QueueUrl\":\"http://localhost:4566/000000000000/q\",\"MessageBody\":\"hi\"}");
|
||||
Schedule schedule = new Schedule();
|
||||
assertEquals("cn-north-1", ScheduleInvoker.regionOf(schedule, "cn-north-1"));
|
||||
schedule.setTarget(target);
|
||||
|
||||
chinaInvoker.invoke(schedule, SCHEDULED_AT);
|
||||
verify(sqsService).sendMessage(eq("http://localhost:4566/000000000000/q"), eq("hi"), eq(0),
|
||||
isNull(), isNull(), any(), eq("cn-north-1"));
|
||||
|
||||
schedule.setArn("arn:aws:scheduler:eu-west-1:000000000000:schedule/default/nightly");
|
||||
assertEquals("eu-west-1", ScheduleInvoker.regionOf(schedule, "cn-north-1"));
|
||||
chinaInvoker.invoke(schedule, SCHEDULED_AT);
|
||||
verify(sqsService).sendMessage(eq("http://localhost:4566/000000000000/q"), eq("hi"), eq(0),
|
||||
isNull(), isNull(), any(), eq("eu-west-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.services.redshift.RedshiftService;
|
||||
import io.floci.aws.services.scheduler.model.Schedule;
|
||||
import io.floci.aws.services.sqs.SqsService;
|
||||
@@ -148,7 +149,7 @@ class SchedulerRedshiftDataDockerIntegrationTest {
|
||||
SchedulerService scopedSchedulerService = mock(SchedulerService.class);
|
||||
when(scopedSchedulerService.listAllSchedules()).thenReturn(List.of(schedule));
|
||||
ScheduleDispatcher dispatcher = new ScheduleDispatcher(
|
||||
scopedSchedulerService, scheduleInvoker, sqsService, config);
|
||||
scopedSchedulerService, scheduleInvoker, sqsService, config, new RegionResolver(config));
|
||||
testDispatchers.add(dispatcher);
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.services.scheduler.model.Schedule;
|
||||
import io.floci.aws.services.sqs.SqsService;
|
||||
import io.restassured.response.Response;
|
||||
@@ -113,12 +114,14 @@ final class SchedulerTestHarness {
|
||||
Schedule schedule = schedulerService.getSchedule(scheduleName, null, REGION);
|
||||
SchedulerService scopedSchedulerService = mock(SchedulerService.class);
|
||||
when(scopedSchedulerService.listAllSchedules()).thenReturn(List.of(schedule));
|
||||
return track(new ScheduleDispatcher(scopedSchedulerService, scheduleInvoker, sqsService, config));
|
||||
return track(new ScheduleDispatcher(scopedSchedulerService, scheduleInvoker, sqsService, config,
|
||||
new RegionResolver(config)));
|
||||
}
|
||||
|
||||
/** A dispatcher over every schedule the service holds. */
|
||||
ScheduleDispatcher unscopedDispatcher() {
|
||||
return track(new ScheduleDispatcher(schedulerService, scheduleInvoker, sqsService, config));
|
||||
return track(new ScheduleDispatcher(schedulerService, scheduleInvoker, sqsService, config,
|
||||
new RegionResolver(config)));
|
||||
}
|
||||
|
||||
String createStateMachine(String name, String definition) {
|
||||
|
||||
Reference in new issue
Block a user