Skip to content

Commit

Permalink
#550 reviewed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zorba71 committed Feb 6, 2024
1 parent 3739ea3 commit 00b1b03
Showing 1 changed file with 34 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ public void setUp() {

@Test
public void splitWithMissingConfigResource(TestContext context) {

// Given
Async async = context.async();
context.assertFalse(queueSplitter.isInitialized());

// When
queueSplitter.initialize().onComplete(event -> {

// Then
context.assertFalse(queueSplitter.isInitialized());
verifySplitStaticNotExecuted(context);
verifySplitWithHeaderNotExecuted(context);
Expand All @@ -62,10 +68,16 @@ public void splitWithMissingConfigResource(TestContext context) {

@Test
public void splitWithValidConfigResource(TestContext context) {

// Given
Async async = context.async();
storage.putMockData(configResourceUri, CONFIG_RESOURCE_VALID);
context.assertFalse(queueSplitter.isInitialized());

// When
queueSplitter.initialize().onComplete(event -> {

// Then
context.assertTrue(queueSplitter.isInitialized());
verifySplitStaticExecuted(context);
verifySplitWithHeaderExecuted(context);
Expand All @@ -76,10 +88,16 @@ public void splitWithValidConfigResource(TestContext context) {

@Test
public void splitWithPartiallyInvalidConfigResource(TestContext context) {

// Given
Async async = context.async();
storage.putMockData(configResourceUri, CONFIG_RESOURCE_INVALID);
context.assertFalse(queueSplitter.isInitialized());

// When
queueSplitter.initialize().onComplete(event -> {

// Then
context.assertTrue(queueSplitter.isInitialized());
verifySplitStaticExecuted(context);
verifySplitWithHeaderNotExecuted(context);
Expand All @@ -91,10 +109,16 @@ public void splitWithPartiallyInvalidConfigResource(TestContext context) {

@Test
public void splitWithQueueNotMatchingAnyConfiguration(TestContext context) {

// Given
Async async = context.async();
storage.putMockData(configResourceUri, CONFIG_RESOURCE_VALID);
context.assertFalse(queueSplitter.isInitialized());

// When
queueSplitter.initialize().onComplete(event -> {

// Then
HttpServerRequest request = mock(HttpServerRequest.class);
when(request.headers()).thenReturn(new HeadersMultiMap());
context.assertEquals("another-queue", queueSplitter.convertToSubQueue("another-queue", request));
Expand All @@ -103,7 +127,9 @@ public void splitWithQueueNotMatchingAnyConfiguration(TestContext context) {
}

@Test
public void configResourceRemovedTriggerRemoveAllExecutorsOld(TestContext context) {
public void configResourceRemovedTriggerRemoveAllExecutors(TestContext context) {

// Given
Async async = context.async();
storage.putMockData(configResourceUri, CONFIG_RESOURCE_VALID);
queueSplitter.initialize().onComplete(event -> {
Expand All @@ -120,6 +146,8 @@ public void resourceChanged(String resourceUri, Buffer resource) {

@Override
public void resourceRemoved(String resourceUri) {

// Then
context.assertFalse(queueSplitter.isInitialized());
verifySplitStaticNotExecuted(context);
verifySplitWithHeaderNotExecuted(context);
Expand All @@ -128,6 +156,7 @@ public void resourceRemoved(String resourceUri) {
}
}, configResourceUri);

// When
JsonObject object = new JsonObject();
object.put("requestUri", configResourceUri);
object.put("type", "remove");
Expand All @@ -136,35 +165,11 @@ public void resourceRemoved(String resourceUri) {
}

@Test
public void configResourceRemovedTriggerRemoveAllExecutors(TestContext context) {
Async async = context.async();
storage.putMockData(configResourceUri, CONFIG_RESOURCE_VALID);
queueSplitter.initialize().onComplete(event -> {
context.assertTrue(queueSplitter.isInitialized());
verifySplitStaticExecuted(context);
verifySplitWithHeaderExecuted(context);
verifySplitWithUrlExecuted(context);

vertx.eventBus().consumer(CONFIG_RESOURCE_CHANGED_ADDRESS, (Handler<Message<JsonObject>>) message -> {
context.assertEquals("remove", message.body().getString("type"));
context.assertFalse(queueSplitter.isInitialized());
verifySplitStaticNotExecuted(context);
verifySplitWithHeaderNotExecuted(context);
verifySplitWithUrlNotExecuted(context);
async.complete();
});
JsonObject object = new JsonObject();
object.put("requestUri", configResourceUri);
object.put("type", "remove");
vertx.eventBus().publish(CONFIG_RESOURCE_CHANGED_ADDRESS, object);
});
}
public void configResourceChangedTriggerNewInitOfExecutors(TestContext context) {

@Test
public void configResourceChangedTriggerNewInitOfExecutorsOld(TestContext context) {
// Given
Async async = context.async();
storage.putMockData(configResourceUri, CONFIG_RESOURCE_VALID);

queueSplitter.initialize().onComplete(event -> {
context.assertTrue(queueSplitter.isInitialized());
verifySplitStaticExecuted(context);
Expand All @@ -177,6 +182,7 @@ public void configResourceChangedTriggerNewInitOfExecutorsOld(TestContext contex

@Override
public void resourceChanged(String resourceUri, Buffer resource) {
// Then
resourceChangedCalls++;
if (resourceChangedCalls == 2) {
context.assertTrue(queueSplitter.isInitialized());
Expand All @@ -192,6 +198,7 @@ public void resourceRemoved(String resourceUri) {
}
}, configResourceUri);

// When
storage.putMockData(configResourceUri, CONFIG_RESOURCE_INVALID);
JsonObject object = new JsonObject();
object.put("requestUri", configResourceUri);
Expand All @@ -200,75 +207,6 @@ public void resourceRemoved(String resourceUri) {
});
}

@Test
@Ignore("to review")
public void configResourceChangedTriggerNewInitOfExecutors1(TestContext context) {
Async async = context.async();
storage.putMockData(configResourceUri, CONFIG_RESOURCE_VALID);

queueSplitter.initialize().onComplete(event -> {

context.assertTrue(queueSplitter.isInitialized());
verifySplitStaticExecuted(context);
verifySplitWithHeaderExecuted(context);
verifySplitWithUrlExecuted(context);

storage.putMockData(configResourceUri, CONFIG_RESOURCE_INVALID);
JsonObject object = new JsonObject();
object.put("requestUri", configResourceUri);
object.put("type", "change");
vertx.eventBus().publish(CONFIG_RESOURCE_CHANGED_ADDRESS, object);

await().atMost(10, SECONDS).until( () -> {
HttpServerRequest request = mock(HttpServerRequest.class);
when(request.headers()).thenReturn(new HeadersMultiMap().add("x-rp-deviceid", "A1B2C3D4E5F6"));
String value = queueSplitter.convertToSubQueue("my-queue-2", request);
System.out.println("await called");
return "my-queue-2".equals(value);
}, equalTo(Boolean.TRUE));

context.assertTrue(queueSplitter.isInitialized());
// verifySplitStaticExecuted(context);
// verifySplitWithHeaderNotExecuted(context);
// verifySplitWithUrlNotExecuted(context);
// async.complete();
});
}

@Test
@Ignore("to review")
public void configResourceChangedTriggerNewInitOfExecutors2(TestContext context) {
Async async = context.async();
storage.putMockData(configResourceUri, CONFIG_RESOURCE_VALID);

AtomicInteger resourceChangedCalls = new AtomicInteger(0);
vertx.eventBus().consumer(CONFIG_RESOURCE_CHANGED_ADDRESS, (Handler<Message<JsonObject>>) message -> {

int counter = resourceChangedCalls.incrementAndGet();
if (counter == 1) {
context.assertEquals("change", message.body().getString("type"));
context.assertFalse(queueSplitter.isInitialized());
verifySplitStaticNotExecuted(context);
verifySplitWithHeaderNotExecuted(context);
verifySplitWithUrlNotExecuted(context);
async.complete();
} else if (counter == 2) {
context.assertEquals("change", message.body().getString("type"));
context.assertTrue(queueSplitter.isInitialized());
verifySplitStaticExecuted(context);
verifySplitWithHeaderExecuted(context);
verifySplitWithUrlExecuted(context);
async.complete();
}
});

storage.putMockData(configResourceUri, CONFIG_RESOURCE_INVALID);
JsonObject object = new JsonObject();
object.put("requestUri", configResourceUri);
object.put("type", "change");
vertx.eventBus().publish(CONFIG_RESOURCE_CHANGED_ADDRESS, object);
}

private void verifySplitStaticExecuted(TestContext context) {
HttpServerRequest request = mock(HttpServerRequest.class);
context.assertEquals("my-queue-1-A", queueSplitter.convertToSubQueue("my-queue-1", request));
Expand Down

0 comments on commit 00b1b03

Please sign in to comment.