forked from sirchia/camel-disruptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
188 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
target/ | ||
/.classpath | ||
/.project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/org.eclipse.core.resources.prefs | ||
/org.eclipse.jdt.core.prefs | ||
/org.eclipse.m2e.core.prefs |
116 changes: 116 additions & 0 deletions
116
src/test/java/com/github/camel/component/disruptor/DisruptorBufferingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright 2012 Riccardo Sirchia | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.github.camel.component.disruptor; | ||
|
||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.component.mock.MockEndpoint; | ||
import org.apache.camel.test.junit4.CamelTestSupport; | ||
import org.junit.Test; | ||
|
||
/** | ||
* This test suite is testing different scenarios where a disruptor is forced to | ||
* buffer exchanges locally until a consumer is registered. | ||
*/ | ||
public class DisruptorBufferingTest extends CamelTestSupport { | ||
|
||
@Test | ||
public void testDisruptorBufferingWhileWaitingOnFirstConsumer() throws Exception { | ||
template.sendBody("disruptor:foo", "A"); | ||
template.sendBody("disruptor:foo", "B"); | ||
template.sendBody("disruptor:foo", "C"); | ||
|
||
DisruptorEndpoint disruptorEndpoint = getMandatoryEndpoint("disruptor:foo", DisruptorEndpoint.class); | ||
|
||
assertEquals(5, disruptorEndpoint.getDisruptor().remainingCapacity()); | ||
|
||
// Add a first consumer on the endpoint | ||
context.addRoutes(new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("disruptor:foo").routeId("bar").to("mock:bar"); | ||
} | ||
}); | ||
|
||
// Now that we have a consumer, the disruptor should send the buffered | ||
// events downstream. Expect to receive the 3 original exchanges. | ||
MockEndpoint mockEndpoint = getMockEndpoint("mock:bar"); | ||
mockEndpoint.expectedMessageCount(3); | ||
mockEndpoint.assertIsSatisfied(200); | ||
} | ||
|
||
@Test | ||
public void testDisruptorBufferingWhileWaitingOnNextConsumer() throws Exception { | ||
template.sendBody("disruptor:foo", "A"); | ||
template.sendBody("disruptor:foo", "B"); | ||
template.sendBody("disruptor:foo", "C"); | ||
|
||
DisruptorEndpoint disruptorEndpoint = getMandatoryEndpoint("disruptor:foo", DisruptorEndpoint.class); | ||
|
||
assertEquals(5, disruptorEndpoint.getDisruptor().remainingCapacity()); | ||
|
||
// Add a first consumer on the endpoint | ||
context.addRoutes(new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("disruptor:foo").routeId("bar1").delay(200).to("mock:bar"); | ||
} | ||
}); | ||
|
||
// Now that we have a consumer, the disruptor should send the buffered | ||
// events downstream. Wait until we have processed at least one | ||
// exchange. | ||
MockEndpoint mockEndpoint = getMockEndpoint("mock:bar"); | ||
mockEndpoint.expectedMinimumMessageCount(1); | ||
mockEndpoint.assertIsSatisfied(200); | ||
|
||
// Stop route and make sure all exchanges have been flushed. | ||
context.stopRoute("bar1"); | ||
mockEndpoint.expectedMessageCount(3); | ||
mockEndpoint.assertIsSatisfied(); | ||
|
||
resetMocks(); | ||
template.sendBody("disruptor:foo", "D"); | ||
template.sendBody("disruptor:foo", "E"); | ||
template.sendBody("disruptor:foo", "F"); | ||
|
||
// Add a new consumer on the endpoint | ||
context.addRoutes(new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("disruptor:foo").routeId("bar2").to("mock:bar"); | ||
} | ||
}); | ||
template.sendBody("disruptor:foo", "G"); | ||
|
||
// Make sure we have received the 3 buffered exchanges plus the one | ||
// added late. | ||
mockEndpoint = getMockEndpoint("mock:bar"); | ||
mockEndpoint.expectedMessageCount(4); | ||
mockEndpoint.assertIsSatisfied(100); | ||
} | ||
|
||
@Override | ||
protected RouteBuilder createRouteBuilder() throws Exception { | ||
return new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("direct:start").routeId("foo").to("disruptor:foo?size=8"); | ||
} | ||
}; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters