下面列出了怎么用org.junit.jupiter.api.Timeout的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
@Timeout(90)
public void testIndexOperation() {
try {
String topic = TestUtils.getDefaultTestTopic(this.getClass());
ConnectorPropertyFactory propertyFactory = CamelElasticSearchPropertyFactory
.basic()
.withTopics(topic)
.withOperation("Index")
.withClusterName(ElasticSearchCommon.DEFAULT_ELASTICSEARCH_CLUSTER)
.withHostAddress(elasticSearch.getHttpHostAddress())
.withIndexName(ElasticSearchCommon.DEFAULT_ELASTICSEARCH_INDEX)
.withTransformsConfig("ElasticSearchTransformer")
.withEntry("type", "org.apache.camel.kafkaconnector.elasticsearch.sink.transform.ConnectRecordValueToMapTransformer")
.withEntry("key", transformKey)
.end();
runTest(propertyFactory);
LOG.debug("Created the consumer ... About to receive messages");
} catch (Exception e) {
LOG.error("ElasticSearch test failed: {}", e.getMessage(), e);
fail(e.getMessage());
}
}
@Test
@Timeout(90)
public void testBasicSendReceive() {
try {
ConnectorPropertyFactory connectorPropertyFactory = CamelSlackPropertyFactory
.basic()
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withChannel(slackChannel)
.withWebhookUrl(webhookUrl);
runTest(connectorPropertyFactory, "Sink test message sent to Slack from testBasicSendReceive");
} catch (Exception e) {
LOG.error("Slack test failed: {}", e.getMessage(), e);
fail(e.getMessage());
}
}
@Test
@Timeout(90)
public void testBasicSendReceiveWithUrl() {
try {
ConnectorPropertyFactory connectorPropertyFactory = CamelSlackPropertyFactory
.basic()
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withUrl(slackChannel)
.append("webhookUrl", webhookUrl)
.buildUrl();
runTest(connectorPropertyFactory, "Sink test message sent to Slack from testBasicSendReceiveWithUrl");
} catch (Exception e) {
LOG.error("Slack test failed: {}", e.getMessage(), e);
fail(e.getMessage());
}
}
@Test
@Timeout(90)
public void testBasicSendReceiveUsingUrl() {
try {
ConnectorPropertyFactory connectorPropertyFactory = CamelFilePropertyFactory.basic()
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withUrl(SINK_DIR)
.append("fileName", FILENAME)
.append("doneFileName", FILENAME + ".done")
.buildUrl();
runTest(connectorPropertyFactory);
} catch (Exception e) {
LOG.error("HTTP test failed: {}", e.getMessage(), e);
fail(e.getMessage());
}
}
@Test
@Timeout(90)
public void testBasicSendReceive() {
try {
ConnectorPropertyFactory connectorPropertyFactory = CamelJMSPropertyFactory
.basic()
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withConnectionProperties(jmsService.getConnectionProperties())
.withDestinationName(SJMS2Common.DEFAULT_JMS_QUEUE);
runTest(connectorPropertyFactory);
} catch (Exception e) {
LOG.error("JMS test failed: {}", e.getMessage(), e);
fail(e.getMessage());
}
}
@Test
@Timeout(90)
public void testBasicSendReceiveUsingUrl() {
try {
ConnectorPropertyFactory connectorPropertyFactory = CamelJMSPropertyFactory
.basic()
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withConnectionProperties(jmsService.getConnectionProperties())
.withUrl(SJMS2Common.DEFAULT_JMS_QUEUE)
.buildUrl();
runTest(connectorPropertyFactory);
} catch (Exception e) {
LOG.error("JMS test failed: {}", e.getMessage(), e);
fail(e.getMessage());
}
}
@Test
@Timeout(10)
public void testIntermediateCatchEventTimerCycle2() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerCycle2.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.addEventListener(countDownListener);
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
assertProcessInstanceActive(processInstance);
// now wait for 1 second for timer to trigger
countDownListener.waitTillCompleted();
assertProcessInstanceActive(processInstance);
ksession.abortProcessInstance(processInstance.getId());
}
@Test
@Timeout(10)
public void testIntermediateTimerParallelGateway() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Timer1", 1);
NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener("Timer2", 1);
NodeLeftCountDownProcessEventListener countDownListener3 = new NodeLeftCountDownProcessEventListener("Timer3", 1);
KieBase kbase = createKnowledgeBase("timer/BPMN2-IntermediateTimerParallelGateway.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
ksession.addEventListener(countDownListener2);
ksession.addEventListener(countDownListener3);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = ksession.startProcess("Evaluation.timer-parallel");
assertProcessInstanceActive(processInstance);
countDownListener.waitTillCompleted();
countDownListener2.waitTillCompleted();
countDownListener3.waitTillCompleted();
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
@DisabledIfSystemProperty(named = "aws-service.instance.type", matches = "remote")
@Test
@Timeout(value = 120)
@RepeatedTest(3)
public void testBasicSendReceiveUsingKafkaStyle() {
try {
Properties amazonProperties = awsService.getConnectionProperties();
ConnectorPropertyFactory testProperties = CamelAWSSQSPropertyFactory
.basic()
.withName("CamelAwssqsSinkConnectorKafkaStyle")
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withAmazonConfig(amazonProperties, CamelAWSSQSPropertyFactory.KAFKA_STYLE)
.withQueueNameOrArn(queueName);
runTest(testProperties);
} catch (Exception e) {
LOG.error("Amazon SQS test failed: {}", e.getMessage(), e);
fail(e.getMessage());
}
}
@Test
@Timeout(10)
public void testIntermediateCatchEventTimerCycle1() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerCycle1.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.addEventListener(countDownListener);
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
assertProcessInstanceActive(processInstance);
// now wait for 1 second for timer to trigger
countDownListener.waitTillCompleted();
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
assertProcessInstanceFinished(processInstance, ksession);
}
@Test
@Timeout(10)
public void testIntermediateCatchEventTimer() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerDuration.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
// now wait for 1 second for timer to trigger
countDownListener.waitTillCompleted();
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
@Test
@Timeout(value = 90)
public void testBasicSendReceive() {
try {
final String sqsQueue = awsSqsClient.getQueue(AWSCommon.DEFAULT_SQS_QUEUE_FOR_SNS);
LOG.info("Created SQS queue {}", sqsQueue);
Properties amazonProperties = service.getConnectionProperties();
ConnectorPropertyFactory connectorPropertyFactory = CamelAWSSNSPropertyFactory.basic()
.withName("CamelAWSSNSSinkConnectorDefault")
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withTopicOrArn(AWSCommon.DEFAULT_SQS_QUEUE_FOR_SNS)
.withSubscribeSNStoSQS(sqsQueue)
.withConfiguration(TestSNSConfiguration.class.getName())
.withAmazonConfig(amazonProperties);
runTest(connectorPropertyFactory);
} catch (Exception e) {
LOG.error("Amazon SNS test failed: {}", e.getMessage(), e);
fail(e.getMessage());
}
}
@Test
@Timeout(value = 90)
public void testBasicSendReceiveUsingKafkaStyle() {
try {
final String sqsQueue = awsSqsClient.getQueue(AWSCommon.DEFAULT_SQS_QUEUE_FOR_SNS);
LOG.info("Created SQS queue {}", sqsQueue);
Properties amazonProperties = service.getConnectionProperties();
ConnectorPropertyFactory connectorPropertyFactory = CamelAWSSNSPropertyFactory.basic()
.withName("CamelAWSSNSSinkKafkaStyleConnector")
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withTopicOrArn(AWSCommon.DEFAULT_SQS_QUEUE_FOR_SNS)
.withSubscribeSNStoSQS(sqsQueue)
.withConfiguration(TestSNSConfiguration.class.getName())
.withAmazonConfig(amazonProperties, CamelAWSSNSPropertyFactory.KAFKA_STYLE);
runTest(connectorPropertyFactory);
} catch (Exception e) {
LOG.error("Amazon SNS test failed: {}", e.getMessage(), e);
fail(e.getMessage());
}
}
@Test
@Timeout(180)
public void testBasicSendReceiveUsingUrl() throws ExecutionException, InterruptedException {
Properties amazonProperties = service.getConnectionProperties();
ConnectorPropertyFactory connectorPropertyFactory = CamelAWSS3PropertyFactory
.basic()
.withKafkaTopic(TestUtils.getDefaultTestTopic(this.getClass()))
.withConfiguration(TestS3Configuration.class.getName())
.withUrl(AWSCommon.DEFAULT_S3_BUCKET)
.append("accessKey", amazonProperties.getProperty(AWSConfigs.ACCESS_KEY))
.append("secretKey", amazonProperties.getProperty(AWSConfigs.SECRET_KEY))
.appendIfAvailable("proxyProtocol", amazonProperties.getProperty(AWSConfigs.PROTOCOL))
.append("region", amazonProperties.getProperty(AWSConfigs.REGION, Regions.US_EAST_1.name()))
.buildUrl();
runTest(connectorPropertyFactory);
}
@Test
@Timeout(90)
public void testBasicSendReceive() throws ExecutionException, InterruptedException {
String connectionBeanRef = String.format("com.mongodb.client.MongoClients#create('mongodb://%s:%d')",
mongoDBService.getHost(),
mongoDBService.getPort());
CamelMongoDBPropertyFactory factory = CamelMongoDBPropertyFactory.basic()
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withConnectionBean("mongo",
BasicConnectorPropertyFactory.classRef(connectionBeanRef))
.withDatabase("testDB")
.withCollection("testRecords")
.withOperation("insert");
runTest(factory);
verifyDocuments("testDB", "testRecords");
}
@Test
@Timeout(90)
public void testFindAll() throws ExecutionException, InterruptedException {
String connectionBeanRef = String.format("com.mongodb.client.MongoClients#create('mongodb://%s:%d')",
mongoDBService.getHost(),
mongoDBService.getPort());
ConnectorPropertyFactory factory = CamelMongoDBPropertyFactory.basic()
.withKafkaTopic(TestUtils.getDefaultTestTopic(this.getClass()))
.withConnectionBean("mongo",
BasicConnectorPropertyFactory.classRef(connectionBeanRef))
.withDatabase("testDatabase")
.withCollection("testCollection")
.withCreateCollection(true);
runTest(factory);
}
@Test
@Timeout(90)
public void testBasicSendReceive() {
try {
String url = localServer.getInetAddress().getHostName() + ":" + HTTP_PORT + "/ckc";
ConnectorPropertyFactory connectorPropertyFactory = CamelHTTPPropertyFactory.basic()
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withHttpUri(url);
runTest(connectorPropertyFactory);
} catch (Exception e) {
LOG.error("HTTP test failed: {} {}", e.getMessage(), e);
fail(e.getMessage(), e);
}
}
@Test
@Timeout(90)
public void testBasicSendReceiveUsingUrl() {
try {
String hostName = localServer.getInetAddress().getHostName() + ":" + HTTP_PORT + "/ckc";
ConnectorPropertyFactory connectorPropertyFactory = CamelHTTPPropertyFactory.basic()
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withUrl(hostName)
.buildUrl();
runTest(connectorPropertyFactory);
} catch (Exception e) {
LOG.error("HTTP test failed: {} {}", e.getMessage(), e);
fail(e.getMessage(), e);
}
}
@Test
@Timeout(180)
public void testBasicProduce() throws ExecutionException, InterruptedException {
ConnectorPropertyFactory factory = CamelSalesforcePropertyFactory.basic()
.withKafkaTopic(TestUtils.getDefaultTestTopic(this.getClass()))
.withUserName(userName)
.withPassword(password)
.withClientId(clientId)
.withClientSecret(clientSecret)
.withRawPayload(true)
.withPackages("org.apache.camel.salesforce.dto")
.withSObjectName("Account")
.withOperationName("createSObject");
runTest(factory);
TestUtils.waitFor(this::waitForRecordCreation);
assertTrue(recordCreated, "The record was not created");
}
@Test
@Timeout(180)
public void testBasicConsume() throws ExecutionException, InterruptedException {
ConnectorPropertyFactory factory = CamelSalesforcePropertyFactory.basic()
.withKafkaTopic(TestUtils.getDefaultTestTopic(this.getClass()))
.withUserName(userName)
.withPassword(password)
.withClientId(clientId)
.withClientSecret(clientSecret)
.withNotifyForFields("ALL")
.withUpdateTopic(true)
.withRawPayload(true)
.withPackages("org.apache.camel.salesforce.dto")
.withSObjectClass("org.apache.camel.salesforce.dto.Account")
.withSObjectQuery("SELECT Id, Name FROM Account")
.withTopicName("CamelKafkaConnectorTopic");
Executors.newCachedThreadPool().submit(this::updateTestAccount);
runBasicTest(factory);
}
@Test
@Timeout(180)
public void testBasicConsumeUsingUrl() throws ExecutionException, InterruptedException {
ConnectorPropertyFactory factory = CamelSalesforcePropertyFactory.basic()
.withKafkaTopic(TestUtils.getDefaultTestTopic(this.getClass()))
.withUserName(userName)
.withPassword(password)
.withClientId(clientId)
.withClientSecret(clientSecret)
.withUrl("CamelKafkaConnectorTopic")
.append("notifyForFields", "ALL")
.append("updateTopic", "true")
.append("rawPayload", "true")
.append("sObjectClass", "org.apache.camel.salesforce.dto.Account")
.append("sObjectQuery", "SELECT Id, Name FROM Account")
.buildUrl();
Executors.newCachedThreadPool().submit(this::updateTestAccount);
runBasicTest(factory);
}
@Test
@Timeout(180)
public void testBasicCDCUsingUrl() throws ExecutionException, InterruptedException {
ConnectorPropertyFactory factory = CamelSalesforcePropertyFactory.basic()
.withKafkaTopic(TestUtils.getDefaultTestTopic(this.getClass()))
.withUserName(userName)
.withPassword(password)
.withClientId(clientId)
.withClientSecret(clientSecret)
.withApiVersion("37.0")
.withUrl("data/AccountChangeEvent")
.append("replayId", "-2")
.append("rawPayload", "true")
.buildUrl();
runBasicTest(factory);
}
@Timeout(90)
@Test
public void testRetrieveFromCassandra() throws ExecutionException, InterruptedException {
String topic = TestUtils.getDefaultTestTopic(this.getClass());
ConnectorPropertyFactory connectorPropertyFactory = CamelCassandraPropertyFactory
.basic()
.withKafkaTopic(topic)
.withHosts(cassandraService.getCassandraHost())
.withPort(cassandraService.getCQL3Port())
.withKeySpace(TestDataDao.KEY_SPACE)
.withResultSetConversionStrategy("ONE")
.withCql(testDataDao.getSelectStatement());
runTest(connectorPropertyFactory);
}
@Disabled("Disabled due to CAMEL-15219")
@Timeout(90)
@Test
public void testRetrieveFromCassandraWithCustomStrategy() throws ExecutionException, InterruptedException {
String topic = TestUtils.getDefaultTestTopic(this.getClass());
ConnectorPropertyFactory connectorPropertyFactory = CamelCassandraPropertyFactory
.basic()
.withKafkaTopic(topic)
.withHosts(cassandraService.getCassandraHost())
.withPort(cassandraService.getCQL3Port())
.withKeySpace(TestDataDao.KEY_SPACE)
.withResultSetConversionStrategy("#:" + TestResultSetConversionStrategy.class.getName())
.withCql(testDataDao.getSelectStatement());
runTest(connectorPropertyFactory);
}
@Test
@Timeout(90)
public void testBasicReceive() {
try {
ConnectorPropertyFactory connectorPropertyFactory = CamelSyslogPropertyFactory
.basic()
.withTopics(TestUtils.getDefaultTestTopic(this.getClass()))
.withHost("localhost")
.withPort(FREE_PORT)
.withProtocol("udp");
runBasicProduceTest(connectorPropertyFactory);
} catch (Exception e) {
LOG.error("Syslog test failed: {} {}", e.getMessage(), e);
fail(e.getMessage(), e);
}
}
@Test
@Timeout(90)
public void testBasicSend() {
try {
ConnectorPropertyFactory connectorPropertyFactory = CamelSyslogPropertyFactory
.basic()
.withKafkaTopic(TestUtils.getDefaultTestTopic(this.getClass()))
.withHost("localhost")
.withPort(FREE_PORT)
.withProtocol("udp");
runBasicStringTest(connectorPropertyFactory);
} catch (Exception e) {
LOG.error("Syslog test failed: {} {}", e.getMessage(), e);
fail(e.getMessage(), e);
}
}
/**
* 对于每一个生产者而言,都应该满足先入先出
*/
@Timeout(TEST_TIMEOUT)
@Test
void testFifo() {
final int producerNum = 4;
final AtomicBoolean stop = new AtomicBoolean();
final LongHolder fail = new LongHolder();
final long[] lastSequences = new long[producerNum];
final FIFOProducer[] producers = new FIFOProducer[producerNum];
for (int index = 0; index < producerNum; index++) {
producers[index] = new FIFOProducer(stop, index, fail, lastSequences);
}
TestUtil.startAndJoin(Arrays.asList(producers), stop, 1000);
Assertions.assertEquals(0, fail.get(), "Observed out of order");
}
/**
* 对于每一个生产者而言,都应该满足先入先出
*/
@Timeout(TEST_TIMEOUT)
@Test
void testFifo() {
final int producerNum = 4;
// 必须使用abort策略,否则生产者无法感知失败
final EventLoop eventLoop = newEventLoop(RejectedExecutionHandlers.abort());
final LongHolder fail = new LongHolder();
final long[] lastSequences = new long[producerNum];
final FIFOProducer[] producers = new FIFOProducer[producerNum];
for (int index = 0; index < producerNum; index++) {
producers[index] = new FIFOProducer(eventLoop, index, fail, lastSequences);
}
TestUtil.startAndJoin(Arrays.asList(producers), eventLoop, 1000);
Assertions.assertEquals(0, fail.get(), "Observed out of order");
}
@Test
@Timeout(10)
public void testIntermediateTimerEventMI() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("After timer", 3);
KieBase kbase = createKnowledgeBase("timer/BPMN2-IntermediateTimerEventMI.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = ksession.startProcess("defaultprocessid");
assertProcessInstanceActive(processInstance);
countDownListener.waitTillCompleted();
assertProcessInstanceActive(processInstance.getId(), ksession);
ksession.abortProcessInstance(processInstance.getId());
assertProcessInstanceAborted(processInstance.getId(), ksession);
}
@Test
@Timeout(10)
public void testTimerStartCycleLegacy() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 2);
KieBase kbase = createKnowledgeBase("BPMN2-TimerStartCycleLegacy.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
final List<String> list = new ArrayList<>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
logger.debug("About to start ###### " + new Date());
assertThat(list.size()).isEqualTo(0);
// then wait 5 times 5oo ms as that is period configured on the process
countDownListener.waitTillCompleted();
ksession.dispose();
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(2);
}