本文整理匯總了Java中org.apache.camel.component.mock.MockEndpoint.getReceivedCounter方法的典型用法代碼示例。如果您正苦於以下問題:Java MockEndpoint.getReceivedCounter方法的具體用法?Java MockEndpoint.getReceivedCounter怎麽用?Java MockEndpoint.getReceivedCounter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.camel.component.mock.MockEndpoint
的用法示例。
在下文中一共展示了MockEndpoint.getReceivedCounter方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDoubleSearchKeepingOld
import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testDoubleSearchKeepingOld() throws Exception {
templateDouble.sendBodyAndHeader(null, TwitterConstants.TWITTER_KEYWORDS, "java");
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
mock.assertIsSatisfied();
List<Exchange> tweets = mock.getExchanges();
for (Exchange e : tweets) {
log.info("Tweet: " + e.getIn().getBody(String.class));
}
// calls the same query again, expecting to receive the same amount of
// tweets, because we told this route to not filter old(consumed) tweets
int total = mock.getReceivedCounter();
templateDouble.sendBodyAndHeader(null, TwitterConstants.TWITTER_KEYWORDS, "java");
// due race condition
assertTrue(mock.getReceivedCounter() >= total);
}
示例2: testGrouped
import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testGrouped() throws Exception {
MockEndpoint result = getMockEndpoint("mock:result");
// we expect 1 or 2 messages since we group all we get in using the same correlation key
result.expectedMinimumMessageCount(1);
// then we sent all the message at once
template.sendBody("direct:start", "100");
template.sendBody("direct:start", "150");
template.sendBody("direct:start", "130");
template.sendBody("direct:start", "200");
assertMockEndpointsSatisfied();
Exchange out = result.getExchanges().get(0);
List<Exchange> grouped = out.getIn().getBody(List.class);
assertTrue("Should be either 2 or 4, was " + grouped.size(), grouped.size() == 2 || grouped.size() == 4);
assertEquals("100", grouped.get(0).getIn().getBody(String.class));
assertEquals("150", grouped.get(1).getIn().getBody(String.class));
// wait a bit for the remainder to come in
Thread.sleep(1000);
if (result.getReceivedCounter() == 2) {
out = result.getExchanges().get(1);
grouped = out.getIn().getBody(List.class);
assertEquals(2, grouped.size());
assertEquals("130", grouped.get(0).getIn().getBody(String.class));
assertEquals("200", grouped.get(1).getIn().getBody(String.class));
}
// END SNIPPET: e2
}
示例3: testAggregateConcurrentPerCorrelationKey
import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
public void testAggregateConcurrentPerCorrelationKey() throws Exception {
ExecutorService service = Executors.newFixedThreadPool(50);
List<Callable<Object>> tasks = new ArrayList<Callable<Object>>();
for (int i = 0; i < size; i++) {
final int id = i % 25;
final int choice = i % 2;
final int count = i;
tasks.add(new Callable<Object>() {
public Object call() throws Exception {
if (choice == 0) {
template.sendBodyAndHeader(uri, "" + count, "id", id);
} else {
template2.sendBodyAndHeader(uri, "" + count, "id", id);
}
return null;
}
});
}
MockEndpoint mock = getMockEndpoint("mock:result");
MockEndpoint mock2 = getMockEndpoint2("mock:result");
// submit all tasks
service.invokeAll(tasks);
service.shutdown();
service.awaitTermination(10, TimeUnit.SECONDS);
int contextCount = mock.getReceivedCounter();
int context2Count = mock2.getReceivedCounter();
assertEquals(25, contextCount + context2Count);
}
示例4: testEverySecondOneFails
import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
public void testEverySecondOneFails() throws Exception {
int size = 200;
ExecutorService service = Executors.newFixedThreadPool(50);
List<Callable<Object>> tasks = new ArrayList<Callable<Object>>();
for (int i = 0; i < size; i++) {
final int id = i % 25;
final int choice = i % 2;
final int count = i;
tasks.add(new Callable<Object>() {
public Object call() throws Exception {
if (choice == 0) {
template.sendBodyAndHeader("direct:everysecondone", "" + count, "id", id);
} else {
template2.sendBodyAndHeader("direct:everysecondone", "" + count, "id", id);
}
return null;
}
});
}
MockEndpoint mock = getMockEndpoint("mock:result");
MockEndpoint mock2 = getMockEndpoint2("mock:result");
// submit all tasks
service.invokeAll(tasks);
service.shutdown();
service.awaitTermination(10, TimeUnit.SECONDS);
int contextCount = mock.getReceivedCounter();
int context2Count = mock2.getReceivedCounter();
assertEquals(25, contextCount + context2Count);
}
示例5: prepareQueue
import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Before
public void prepareQueue() throws InterruptedException {
// make sure the queue is empty before test
template.sendBodyAndHeader(ironMQEndpoint, null, IronMQConstants.OPERATION, IronMQConstants.CLEARQUEUE);
long start = System.currentTimeMillis();
int noOfBlocks = 0;
ArrayList<String> list = new ArrayList<String>();
for (int i = 1; i <= NO_OF_MESSAGES; i++) {
String payloadToSend = PAYLOAD.replace("#", "" + i);
list.add(payloadToSend);
if (i % 100 == 0) {
noOfBlocks++;
System.out.println("sending blok " + noOfBlocks);
template.sendBody(sedaEndpoint, list.toArray(new String[0]));
list.clear();
}
}
MockEndpoint mockEndpoint = getMockEndpoint("mock:iron");
while (mockEndpoint.getReceivedCounter() != noOfBlocks) {
log.info("Waiting for queue to fill up. Current size is " + mockEndpoint.getReceivedCounter() * 100);
Thread.sleep(1000);
}
long delta = System.currentTimeMillis() - start;
int seconds = (int)delta / 1000;
int msgPrSec = (int)(NO_OF_MESSAGES / seconds);
log.info("IronMQPerformanceTest: Took: " + seconds + " seconds to produce " + NO_OF_MESSAGES + " messages. Which is " + msgPrSec + " messages pr. second");
}
示例6: testQuartzSuspend
import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testQuartzSuspend() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
assertMockEndpointsSatisfied();
context.suspendRoute("foo");
int size = mock.getReceivedCounter();
resetMocks();
mock.expectedMessageCount(0);
mock.assertIsSatisfied(3000);
assertEquals("Should not schedule when suspended", size, size);
resetMocks();
mock.expectedMinimumMessageCount(1);
context.resumeRoute("foo");
assertMockEndpointsSatisfied();
}
示例7: testQuartzSuspend
import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testQuartzSuspend() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
assertMockEndpointsSatisfied();
context.stopRoute("foo");
int size = mock.getReceivedCounter();
resetMocks();
mock.expectedMessageCount(0);
mock.assertIsSatisfied(3000);
assertEquals("Should not schedule when stopped", size, size);
resetMocks();
mock.expectedMinimumMessageCount(1);
context.startRoute("foo");
assertMockEndpointsSatisfied();
}
示例8: testQuartzStop
import org.apache.camel.component.mock.MockEndpoint; //導入方法依賴的package包/類
@Test
public void testQuartzStop() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
assertMockEndpointsSatisfied();
context.stopRoute("foo");
int size = mock.getReceivedCounter();
resetMocks();
mock.expectedMessageCount(0);
mock.assertIsSatisfied(3000);
assertEquals("Should not schedule when stopped", size, size);
resetMocks();
mock.expectedMinimumMessageCount(1);
context.startRoute("foo");
assertMockEndpointsSatisfied();
}