mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(pipes): move library usages to imports (#3901)
This commit is contained in:
1 parent
8e709b908b
commit
5a59456b2e
5 files changed
+33
-24
No files matched your search
@@ -27,6 +27,7 @@ import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
@@ -184,7 +185,7 @@ class KarapaceManagerTest {
|
||||
Map.of(REST_PORT, new EndpointInfo("localhost", 1)));
|
||||
when(lifecycleManager.createAndStart(any())).thenReturn(info);
|
||||
|
||||
org.junit.jupiter.api.Assertions.assertThrows(IllegalStateException.class,
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> manager.ensureStarted("broker-1:9092"));
|
||||
|
||||
verify(lifecycleManager).stopAndRemove("container-1", null);
|
||||
|
||||
+9
-7
@@ -3,19 +3,21 @@ package io.github.hectorvent.floci.services.pipes;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.services.msk.MskService;
|
||||
import io.github.hectorvent.floci.services.pipes.model.Pipe;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -30,9 +32,9 @@ class PipesKafkaConsumerManagerTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mskService = Mockito.mock(MskService.class);
|
||||
karapaceManager = Mockito.mock(KarapaceManager.class);
|
||||
restClient = Mockito.mock(PipesKafkaRestClient.class);
|
||||
mskService = mock(MskService.class);
|
||||
karapaceManager = mock(KarapaceManager.class);
|
||||
restClient = mock(PipesKafkaRestClient.class);
|
||||
manager = new PipesKafkaConsumerManager(mskService, karapaceManager, restClient);
|
||||
}
|
||||
|
||||
@@ -55,7 +57,7 @@ class PipesKafkaConsumerManagerTest {
|
||||
URI.create("http://localhost:8082/consumers/g/instances/instance-1"));
|
||||
when(karapaceManager.ensureStarted("broker-1:9092")).thenReturn(restBaseUri);
|
||||
when(restClient.createConsumer(eq(restBaseUri), anyString(), anyString())).thenReturn(handle);
|
||||
Mockito.doThrow(new RuntimeException("subscribe failed"))
|
||||
doThrow(new RuntimeException("subscribe failed"))
|
||||
.when(restClient).subscribe(eq(handle), anyList());
|
||||
|
||||
assertThrows(RuntimeException.class, () -> manager.poll(pipe));
|
||||
@@ -197,7 +199,7 @@ class PipesKafkaConsumerManagerTest {
|
||||
|
||||
String fallbackGroupId = manager.resolveConsumerGroupId(fallback);
|
||||
assertEquals(fallbackGroupId, manager.resolveConsumerGroupId(fallback));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(
|
||||
assertTrue(
|
||||
fallbackGroupId.startsWith("floci-pipes-orders-pipe-"),
|
||||
"Expected generated consumer group id prefix, got: " + fallbackGroupId);
|
||||
}
|
||||
|
||||
+5
-3
@@ -6,6 +6,8 @@ import org.junit.jupiter.api.*;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
@@ -119,7 +121,7 @@ class PipesPollerIntegrationTest {
|
||||
return;
|
||||
}
|
||||
}
|
||||
org.junit.jupiter.api.Assertions.fail("Source queue should be drained");
|
||||
fail("Source queue should be drained");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -270,7 +272,7 @@ class PipesPollerIntegrationTest {
|
||||
}
|
||||
assertTrue(body.contains("match-1"),
|
||||
"Target should contain the matching message");
|
||||
org.junit.jupiter.api.Assertions.assertFalse(body.contains("no-match"),
|
||||
assertFalse(body.contains("no-match"),
|
||||
"Target should NOT contain the non-matching message");
|
||||
}
|
||||
|
||||
@@ -294,7 +296,7 @@ class PipesPollerIntegrationTest {
|
||||
return;
|
||||
}
|
||||
}
|
||||
org.junit.jupiter.api.Assertions.fail(
|
||||
fail(
|
||||
"Source queue should be drained (non-matching messages deleted per AWS behavior)");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -26,6 +27,8 @@ import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -173,11 +176,11 @@ class PipesPollerTest {
|
||||
void pollKafka_doesNotCommitWhenDeliveryFails() throws Exception {
|
||||
Pipe pipe = selfManagedKafkaPipe();
|
||||
KafkaRecordDto record = kafkaRecord("orders", 0, 7L, null,
|
||||
"{\"status\":\"active\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
"{\"status\":\"active\"}".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
when(kafkaConsumerManager.poll(pipe)).thenReturn(List.of(record));
|
||||
when(kafkaConsumerManager.resolveBootstrapServers(pipe)).thenReturn("broker-1:9092");
|
||||
org.mockito.Mockito.doThrow(new RuntimeException("boom"))
|
||||
doThrow(new RuntimeException("boom"))
|
||||
.when(targetInvoker).invoke(eq(pipe), anyString(), eq("us-east-1"));
|
||||
|
||||
poller.pollKafka(pipe, "us-east-1");
|
||||
@@ -189,13 +192,13 @@ class PipesPollerTest {
|
||||
void pollKafka_commitsDeliveredPrefixWhenLaterRecordFails() throws Exception {
|
||||
Pipe pipe = selfManagedKafkaPipe();
|
||||
KafkaRecordDto first = kafkaRecord("orders", 0, 0L, null,
|
||||
"{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
"{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(StandardCharsets.UTF_8));
|
||||
KafkaRecordDto second = kafkaRecord("orders", 0, 1L, null,
|
||||
"{\"status\":\"active\",\"id\":\"order-2\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
"{\"status\":\"active\",\"id\":\"order-2\"}".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
when(kafkaConsumerManager.poll(pipe)).thenReturn(List.of(first, second));
|
||||
when(kafkaConsumerManager.resolveBootstrapServers(pipe)).thenReturn("broker-1:9092");
|
||||
org.mockito.Mockito.doNothing()
|
||||
doNothing()
|
||||
.doThrow(new RuntimeException("boom"))
|
||||
.when(targetInvoker).invoke(eq(pipe), anyString(), eq("us-east-1"));
|
||||
|
||||
@@ -216,13 +219,13 @@ class PipesPollerTest {
|
||||
Pipe pipe = selfManagedKafkaPipe();
|
||||
when(kafkaConsumerManager.resolveBatchSize(eq(pipe), anyInt())).thenReturn(1);
|
||||
KafkaRecordDto first = kafkaRecord("orders", 0, 0L, null,
|
||||
"{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
"{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(StandardCharsets.UTF_8));
|
||||
KafkaRecordDto second = kafkaRecord("orders", 0, 1L, null,
|
||||
"{\"status\":\"active\",\"id\":\"order-2\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
"{\"status\":\"active\",\"id\":\"order-2\"}".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
when(kafkaConsumerManager.poll(pipe)).thenReturn(List.of(first, second));
|
||||
when(kafkaConsumerManager.resolveBootstrapServers(pipe)).thenReturn("broker-1:9092");
|
||||
org.mockito.Mockito.doThrow(new RuntimeException("boom"))
|
||||
doThrow(new RuntimeException("boom"))
|
||||
.doNothing()
|
||||
.when(targetInvoker).invoke(eq(pipe), anyString(), eq("us-east-1"));
|
||||
|
||||
@@ -252,15 +255,15 @@ class PipesPollerTest {
|
||||
void pollKafka_lambdaCommitsSuccessfulPrefixBeforeLaterFailure() throws Exception {
|
||||
Pipe pipe = lambdaSelfManagedKafkaPipe();
|
||||
KafkaRecordDto first = kafkaRecord("orders", 0, 0L, null,
|
||||
"{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
"{\"status\":\"active\",\"id\":\"order-1\"}".getBytes(StandardCharsets.UTF_8));
|
||||
KafkaRecordDto skipped = kafkaRecord("orders", 0, 1L, null,
|
||||
"{\"status\":\"inactive\",\"id\":\"order-2\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
"{\"status\":\"inactive\",\"id\":\"order-2\"}".getBytes(StandardCharsets.UTF_8));
|
||||
KafkaRecordDto failing = kafkaRecord("orders", 0, 2L, null,
|
||||
"{\"status\":\"active\",\"id\":\"order-3\"}".getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
"{\"status\":\"active\",\"id\":\"order-3\"}".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
when(kafkaConsumerManager.poll(pipe)).thenReturn(List.of(first, skipped, failing));
|
||||
when(kafkaConsumerManager.resolveBootstrapServers(pipe)).thenReturn("broker-1:9092");
|
||||
org.mockito.Mockito.doNothing()
|
||||
doNothing()
|
||||
.doThrow(new RuntimeException("boom"))
|
||||
.when(targetInvoker).invoke(eq(pipe), anyString(), eq("us-east-1"));
|
||||
|
||||
|
||||
Reference in new issue
Block a user