Java Code Examples for org.wso2.carbon.databridge.commons.Event#setMetaData()
The following examples show how to use
org.wso2.carbon.databridge.commons.Event#setMetaData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataPublisher.java From attic-stratos with Apache License 2.0 | 6 votes |
public void publish(DataContext dataContext) { Event event = new Event(); event.setTimeStamp(new Date().getTime()); event.setMetaData(dataContext.getMetaData()); event.setPayloadData(dataContext.getPayloadData()); try { dataPublisher.publish(streamDefinition.getName(), streamDefinition.getVersion(), event); } catch (AgentException e) { String errorMsg = "Error in publishing event"; log.error(errorMsg, e); // no need to throw here } }
Example 2
Source File: Wso2EventTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing wso2event publisher with custom mapping formatting") public void wso2EventPublisherMapTestWithCustomMappingScenario() throws Exception { final int messageCount = 3; String samplePath = "outputflows" + File.separator + "sample0058"; Wso2EventServer wso2EventServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); List<EventDto> events = new ArrayList<>(); EventDto eventDto = new EventDto(); eventDto.setEventStreamId("org.wso2.event.sensor.stream:1.0.0"); eventDto.setAttributeValues(new String[]{"199008131245", "false", "100", "temperature", "23.45656", "7.12324", "100.34", "23.4545"}); EventDto eventDto2 = new EventDto(); eventDto2.setEventStreamId("org.wso2.event.sensor.stream:1.0.0"); eventDto2.setAttributeValues(new String[]{"199008131245", "false", "101", "temperature", "23.45656", "7.12324", "100.34", "23.4545"}); EventDto eventDto3 = new EventDto(); eventDto3.setEventStreamId("org.wso2.event.sensor.stream:1.0.0"); eventDto3.setAttributeValues(new String[]{"199008131245", "false", "103", "temperature", "23.45656", "7.12324", "100.34", "23.4545"}); events.add(eventDto); events.add(eventDto2); events.add(eventDto3); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); String streamDefinitionMapAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream.map_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionMapAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 2); //Add eventPublisher String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "eventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); wso2EventServer.startServer(); Thread.sleep(1000); eventSimulatorAdminServiceClient.sendEvent(eventDto); eventSimulatorAdminServiceClient.sendEvent(eventDto2); eventSimulatorAdminServiceClient.sendEvent(eventDto3); Thread.sleep(1000); Assert.assertEquals(wso2EventServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); int counter = 0; for (Event currentEvent : wso2EventServer.getPreservedEventList()) { Event event = new Event(); //Mapped stream name is org.wso2.event.sensor.stream.map:1.0.0 event.setStreamId("org.wso2.event.sensor.stream.map:1.0.0"); //first four attributes are meta data event.setMetaData(Arrays.copyOfRange(events.get(counter).getAttributeValues(), 0, 4)); //next two attributes are correlation data event.setCorrelationData(Arrays.copyOfRange(events.get(counter).getAttributeValues(), 4, 6)); //final two attributes are payload event.setPayloadData(Arrays.copyOfRange(events.get(counter).getAttributeValues(), 6, 8)); currentEvent.setTimeStamp(0); Assert.assertEquals(currentEvent.toString(), event.toString(), "Mapping is incorrect!"); counter++; } wso2EventServer.stop(); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream.map", "1.0.0"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("eventPublisher.xml"); }
Example 3
Source File: CEP1502TestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing http receiver with JSON formatted event with mapping enabled and default values set") public void httpJSONMappingTestScenario() throws Exception { final int messageCount = 3; String samplePath = "patches" + File.separator + "CEP1502"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.json.mapped.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add Http JSON EventReceiver with mapping enabled and default values set String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "jsonDefaultMapper.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add WSO2Event EventPublisher String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(10000); HttpEventPublisherClient.publish("http://localhost:" + CEPIntegrationTestConstants.HTTP_PORT + "/endpoints/jsonDefaultMapper", "admin", "admin", samplePath, "httpReceiver.txt"); //wait while all stats are published Thread.sleep(5000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.json.mapped.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("jsonDefaultMapper.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); Thread.sleep(2000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.json.mapped.stream:1.0.0"); event.setMetaData(new Object[]{"P6", 1}); event.setCorrelationData(new Object[]{"NF525004", 4094}); event.setPayloadData(new Object[]{"2016-04-08 11:52:42", 1356, 10, "2016-04-08 11:52:48", 1356, 1, "2016-04-08 11:52:54", 0, 0}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.json.mapped.stream:1.0.0"); event2.setMetaData(new Object[]{"P6", 1}); event2.setCorrelationData(new Object[]{"NF525005", 4094}); event2.setPayloadData(new Object[]{"2016-04-08 11:52:42", 1356, 10, "2016-04-08 11:52:48", 1356, 1, "2016-04-08 11:52:54", 0, 0}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.json.mapped.stream:1.0.0"); event3.setMetaData(new Object[]{"P6", 1}); event3.setCorrelationData(new Object[]{"NF525005", 4096}); event3.setPayloadData(new Object[]{"2016-04-08 11:52:42", 1356, 10, "2016-04-08 11:52:48", 1356, 1, "2016-04-08 11:53:20", 0, 20}); eventList.add(event3); try { Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Default value not set properly!"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 4
Source File: JMSTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing activemq jms receiver with waiting time. Due to large wating time lisnter should " + "not consume any messages from ActiveMQ") public void jmsMapTestWithWaitingTime() throws Exception { String samplePath = "inputflows" + File.separator + "sample0009"; System.out.println("====================My Test==========================="); String configFilePath = getTestArtifactLocation() + CEPIntegrationTestConstants .RELATIVE_PATH_TO_TEST_ARTIFACTS + samplePath + File.separator + "input-event-adapters.xml"; configFilePath = configFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator)); File configFile = new File(configFilePath); File targetConfigFile = new File(serverManager.getCarbonHome() + File.separator + "repository" + File .separator + "conf" + File.separator + "input-event-adapters.xml"); serverManager.applyConfiguration(configFile, targetConfigFile); String loggedInSessionCookie = getSessionCookie(); eventReceiverAdminServiceClient = configurationUtil.getEventReceiverAdminServiceClient( backendURL, loggedInSessionCookie); eventStreamManagerAdminServiceClient = configurationUtil.getEventStreamManagerAdminServiceClient( backendURL, loggedInSessionCookie); eventPublisherAdminServiceClient = configurationUtil.getEventPublisherAdminServiceClient( backendURL, loggedInSessionCookie); Thread.sleep(45000); int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); // Add StreamDefinition. String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, SENSOR_STREAM_JSON); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); // Add JMS Map EventReceiver without mapping. String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, JMS_RECEIVER_MAP); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); // Add Wso2event EventPublisher. String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, WSO2_EVENT_PUBLISHER); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver. Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Wait for server to start and publish. Thread.sleep(5000); JMSPublisherClient.publish("topicMap", "csv", samplePath, "topicMap.csv"); // Wait while all stats are published. Thread.sleep(5000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration(JMS_RECEIVER_MAP); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration(WSO2_EVENT_PUBLISHER); Thread.sleep(2000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId(SENSOR_STREAM); event.setMetaData(new Object[]{19900813115534l, false, 601, "temperature"}); event.setCorrelationData(new Object[]{90.34344, 20.44345}); event.setPayloadData(new Object[]{2.3f, 20.44345}); eventList.add(event); try { // No messages should be received due to large listener waiting time Assert.assertEquals(agentServer.getMsgCount(), 0, "Messages consumed by listener!!"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 5
Source File: KafkaTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing Kafka receiver with invalid events") public void KafkaInvalidEventTestScenario() throws Exception { final int messageCount = 6; String samplePath = "inputflows" + File.separator + "sample0018"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); // Add StreamDefinition. String streamDefinition = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinition); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), ++startESCount); // Add Kafka JSON EventReceiver without mapping. String eventReceiver = getXMLArtifactConfiguration(samplePath, "kafkaReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiver); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), ++startERCount); // Add Wso2event EventPublisher. String eventPublisher = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisher); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), ++startEPCount); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Wait till the server to completely start (until Starting polling event receivers & Kafka Connection). Thread.sleep(60000); try { KafkaEventPublisherClient.publish("localhost:9092", "sensordata", samplePath, "validEvents001.txt"); KafkaEventPublisherClient.publish("localhost:9092", "sensordata", samplePath, "invalidEvents.txt"); KafkaEventPublisherClient.publish("localhost:9092", "sensordata", samplePath, "validEvents002.txt"); // Wait while all stats are published Thread.sleep(10000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{4354643L, false, 701, "temperature"}); event.setCorrelationData(new Object[]{4.504343, 20.44345}); event.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{4354643L, false, 702, "temperature"}); event2.setCorrelationData(new Object[]{4.504343, 20.44345}); event2.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{4354643L, false, 703, "temperature"}); event3.setCorrelationData(new Object[]{4.504343, 20.44345}); event3.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event3); Event event4 = new Event(); event4.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event4.setMetaData(new Object[]{4354643L, false, 704, "temperature"}); event4.setCorrelationData(new Object[]{4.504343, 20.44345}); event4.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event4); Event event5 = new Event(); event5.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event5.setMetaData(new Object[]{4354643L, false, 705, "temperature"}); event5.setCorrelationData(new Object[]{4.504343, 20.44345}); event5.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event5); Event event6 = new Event(); event6.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event6.setMetaData(new Object[]{4354643L, false, 706, "temperature"}); event6.setCorrelationData(new Object[]{4.504343, 20.44345}); event6.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event6); Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Mapping is incorrect!"); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("kafkaReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 6
Source File: HttpTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing http receiver with JSON formatted event") public void httpJSONTestScenario() throws Exception { final int messageCount = 3; String samplePath = "inputflows" + File.separator + "sample0001"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add Http JSON EventReceiver without mapping String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "httpReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add Wso2event EventPublisher String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(10000); HttpEventPublisherClient.publish("http://localhost:" + CEPIntegrationTestConstants.HTTP_PORT + "/endpoints/httpReceiver", "admin", "admin", samplePath, "httpReceiver.txt"); //wait while all stats are published Thread.sleep(30000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("httpReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); Thread.sleep(2000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{4354643l, false, 701, "temperature"}); event.setCorrelationData(new Object[]{4.504343, 20.44345}); event.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{4354643l, false, 702, "temperature"}); event2.setCorrelationData(new Object[]{4.504343, 20.44345}); event2.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{4354643l, false, 703, "temperature"}); event3.setCorrelationData(new Object[]{4.504343, 20.44345}); event3.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event3); try { Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Mapping is incorrect!"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 7
Source File: HttpTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing http receiver with JSON formatted event with mapping enabled") public void httpJSONMappingTestScenario() throws Exception { final int messageCount = 3; String samplePath = "inputflows" + File.separator + "sample0002"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add Http JSON EventReceiver with mapping String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "httpReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add Wso2event EventPublisher String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(10000); HttpEventPublisherClient.publish("http://localhost:" + CEPIntegrationTestConstants.HTTP_PORT + "/endpoints/httpReceiver", "admin", "admin", samplePath, "httpReceiver.txt"); //wait while all stats are published Thread.sleep(5000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("httpReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); Thread.sleep(2000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{19900813115534l, false, 501, "temperature"}); event.setCorrelationData(new Object[]{90.34344, 20.44345}); event.setPayloadData(new Object[]{2.3f, 20.44345}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{19900813115534l, false, 502, "temperature"}); event2.setCorrelationData(new Object[]{90.34344, 20.44345}); event2.setPayloadData(new Object[]{2.3f, 20.44345}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{19900813115534l, false, 503, "temperature"}); event3.setCorrelationData(new Object[]{90.34344, 20.44345}); event3.setPayloadData(new Object[]{2.3f, 20.44345}); eventList.add(event3); try { Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Mapping is incorrect!"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 8
Source File: HttpTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing http receiver with XML formatted event") public void httpXMLTestScenario() throws Exception { final int messageCount = 3; String samplePath = "inputflows" + File.separator + "sample0003"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add Http XML EventReceiver String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "httpReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add Wso2event EventPublisher String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(10000); HttpEventPublisherClient.publish("http://localhost:" + CEPIntegrationTestConstants.HTTP_PORT + "/endpoints/httpReceiver", "admin", "admin", samplePath, "httpReceiver.txt"); //wait while all stats are published Thread.sleep(5000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("httpReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); Thread.sleep(2000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{199008131245l, true, 401, "temperature"}); event.setCorrelationData(new Object[]{4.504343, 1.23434}); event.setPayloadData(new Object[]{6.6f, 20.44345}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{199008131245l, true, 402, "temperature"}); event2.setCorrelationData(new Object[]{4.504343, 1.23434}); event2.setPayloadData(new Object[]{6.6f, 20.44345}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{199008131245l, true, 403, "temperature"}); event3.setCorrelationData(new Object[]{4.504343, 1.23434}); event3.setPayloadData(new Object[]{6.6f, 20.44345}); eventList.add(event3); try { Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Mapping is incorrect!"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 9
Source File: HttpTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing http receiver with XML formatted event with mapping enabled") public void httpXMLMappingTestScenario() throws Exception { final int messageCount = 3; String samplePath = "inputflows" + File.separator + "sample0004"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add Http XML EventReceiver with mapping String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "httpReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add Wso2event EventPublisher String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(10000); HttpEventPublisherClient.publish("http://localhost:" + CEPIntegrationTestConstants.HTTP_PORT + "/endpoints/httpReceiver", "admin", "admin", samplePath, "httpReceiver.txt"); //wait while all stats are published Thread.sleep(5000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{19900813115534l, true, 502, "temperature"}); event.setCorrelationData(new Object[]{4.504343, 1.23434}); event.setPayloadData(new Object[]{6.6f, 20.44345}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{19900813115534l, true, 501, "temperature"}); event2.setCorrelationData(new Object[]{4.504343, 1.23434}); event2.setPayloadData(new Object[]{6.6f, 20.44345}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{19900813115534l, true, 503, "temperature"}); event3.setCorrelationData(new Object[]{4.504343, 1.23434}); event3.setPayloadData(new Object[]{6.6f, 20.44345}); eventList.add(event3); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("httpReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); Thread.sleep(2000); try { Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Mapping is incorrect!"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 10
Source File: HttpTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing http receiver with Text formatted event") public void httpTextTestScenario() throws Exception { final int messageCount = 3; String samplePath = "inputflows" + File.separator + "sample0005"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add Http Text EventReceiver String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "httpReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add Wso2event EventPublisher String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(10000); HttpEventPublisherClient.publish("http://localhost:" + CEPIntegrationTestConstants.HTTP_PORT + "/endpoints/httpReceiver", "admin", "admin", samplePath, "httpReceiver.txt"); //wait while all stats are published Thread.sleep(5000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("httpReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); Thread.sleep(2000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{19900813115534l, false, 100, "temperature"}); event.setCorrelationData(new Object[]{20.44345, 5.443435}); event.setPayloadData(new Object[]{8.9f, 1.23434}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{19900813115534l, false, 101, "temperature"}); event2.setCorrelationData(new Object[]{20.44345, 5.443435}); event2.setPayloadData(new Object[]{8.9f, 1.23434}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{19900813115534l, false, 102, "temperature"}); event3.setCorrelationData(new Object[]{20.44345, 5.443435}); event3.setPayloadData(new Object[]{8.9f, 1.23434}); eventList.add(event3); try { Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Mapping is incorrect!"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 11
Source File: HttpTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing http receiver with Text formatted event with mapping enabled") public void httpTextMappingTestScenario() throws Exception { final int messageCount = 3; String samplePath = "inputflows" + File.separator + "sample0006"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add Http Text EventReceiver with mapping String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "httpReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add Wso2event EventPublisher String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(10000); HttpEventPublisherClient.publish("http://localhost:" + CEPIntegrationTestConstants.HTTP_PORT + "/endpoints/httpReceiver", "admin", "admin", samplePath, "httpReceiver.txt"); //wait while all stats are published Thread.sleep(5000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("httpReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); Thread.sleep(2000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{19900813115534l, false, 100, "temperature"}); event.setCorrelationData(new Object[]{20.44345, 5.443435}); event.setPayloadData(new Object[]{8.9f, 1.23434}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{19900813115534l, false, 101, "temperature"}); event2.setCorrelationData(new Object[]{20.44345, 5.443435}); event2.setPayloadData(new Object[]{8.9f, 1.23434}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{19900813115534l, false, 103, "temperature"}); event3.setCorrelationData(new Object[]{20.44345, 5.443435}); event3.setPayloadData(new Object[]{8.9f, 1.23434}); eventList.add(event3); try { Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Mapping is incorrect!"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 12
Source File: HttpTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing http receiver with secure http request") public void httpsTestScenario() throws Exception { final int messageCount = 3; String samplePath = "inputflows" + File.separator + "sample0021"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add Http JSON EventReceiver without mapping String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "httpReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add Wso2event EventPublisher String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(10000); HttpEventPublisherClient.publish("https://localhost:" + CEPIntegrationTestConstants.HTTPS_PORT + "/endpoints/httpReceiver", "admin", "admin", samplePath, "httpReceiver.txt"); //wait while all stats are published Thread.sleep(30000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("httpReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); Thread.sleep(2000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{4354643l, false, 701, "temperature"}); event.setCorrelationData(new Object[]{4.504343, 20.44345}); event.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{4354643l, false, 702, "temperature"}); event2.setCorrelationData(new Object[]{4.504343, 20.44345}); event2.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{4354643l, false, 703, "temperature"}); event3.setCorrelationData(new Object[]{4.504343, 20.44345}); event3.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event3); try { Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Mapping is incorrect!"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 13
Source File: HttpTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing http receiver with secure http request with xml custom attribute mapping") public void httpsTestScenarioWithXMLAttributeMapping() throws Exception { final int messageCount = 3; String samplePath = "inputflows" + File.separator + "sample0023"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add Http JSON EventReceiver without mapping String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "httpReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add Wso2event EventPublisher String eventPublisherConfig = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(10000); HttpEventPublisherClient.publish("https://localhost:" + CEPIntegrationTestConstants.HTTPS_PORT + "/endpoints/httpReceiver", "admin", "admin", samplePath, "httpReceiver.txt"); //wait while all stats are published Thread.sleep(30000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("httpReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); Thread.sleep(2000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{19900813115534l, true, 502, "temperature"}); event.setCorrelationData(new Object[]{4.504343, 1.23434}); event.setPayloadData(new Object[]{6.6f, 20.44345}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{19900813115534l, true, 501, "temperature"}); event2.setCorrelationData(new Object[]{4.504343, 1.23434}); event2.setPayloadData(new Object[]{6.6f, 20.44345}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{19900813115534l, true, 503, "temperature"}); event3.setCorrelationData(new Object[]{4.504343, 1.23434}); event3.setPayloadData(new Object[]{6.6f, 20.44345}); eventList.add(event3); try { Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Mapping is incorrect!"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 14
Source File: FileTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing File receiver with event") public void FileTestScenario() throws Exception { ServerConfigurationManager serverManager = new ServerConfigurationManager(cepServer); String samplePath = "inputflows" + File.separator + "sample0017"; String destinationFilePath = serverManager.getCarbonHome() + File.separator + "repository" + File.separator + "logs" + File.separator + "fileLogs.txt"; File file = new File(destinationFilePath); //Create new file even if it exists if (file.exists()) { file.delete(); } file.createNewFile(); int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add File EventReceiver without mapping String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "fileReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig.replace("$testFilePath", destinationFilePath)); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add Wso2event EventPublisher String eventPublisherConfig2 = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig2); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(2000); FilePublisherClient.publish(destinationFilePath, samplePath, "fileReceiver.txt"); //File adapter is a poling adapter and it takes 40 seconds to load Thread.sleep(40000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("fileReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); file.delete(); Thread.sleep(2000); List<String> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{4354643, true, 100, "temperature"}); event.setCorrelationData(new Object[]{90.34344, 5.443435}); event.setPayloadData(new Object[]{8.9f, 20.44345}); eventList.add(event.toString()); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{4354653, false, 101, "temperature"}); event2.setCorrelationData(new Object[]{90.34344, 5.443435}); event2.setPayloadData(new Object[]{8.9f, 20.44345}); eventList.add(event2.toString()); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{4354343, true, 102, "temperature"}); event3.setCorrelationData(new Object[]{90.34344, 5.443435}); event3.setPayloadData(new Object[]{8.9f, 20.44345}); eventList.add(event3.toString()); try { Assert.assertEquals(agentServer.getMsgCount(), eventList.size(), "Incorrect number of messages consumed!"); for (Event currentEvent : agentServer.getPreservedEventList()) { currentEvent.setTimeStamp(0); Assert.assertTrue(eventList.contains(currentEvent.toString()), "Mapping is incorrect!" ); } } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 15
Source File: SOAPTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing soap receiver with XML formatted event") public void SOAPXMLTestScenario() throws Exception { String samplePath = "inputflows" + File.separator + "sample0014"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); //Add StreamDefinition String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); //Add SOAP JSON EventReceiver without mapping String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "soapReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); //Add Wso2event EventPublisher String eventPublisherConfig2 = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig2); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Let the server start Thread.sleep(10000); SOAPEventPublisherClient.publish("http://localhost:" + CEPIntegrationTestConstants.HTTP_PORT + "/services/soapReceiver/receive", samplePath, "soapReceiver.txt"); //wait while all stats are published Thread.sleep(30000); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("soapReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); Thread.sleep(2000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{4354643, true, 100, "data1"}); event.setCorrelationData(new Object[]{90.34344, 5.443435}); event.setPayloadData(new Object[]{8.9f, 20.44345}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{4354653, false, 101, "data1"}); event2.setCorrelationData(new Object[]{90.34344, 5.443435}); event2.setPayloadData(new Object[]{8.9f, 20.44345}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{4354343, true, 102, "data1"}); event3.setCorrelationData(new Object[]{90.34344, 5.443435}); event3.setPayloadData(new Object[]{8.9f, 20.44345}); eventList.add(event3); try { Assert.assertEquals(agentServer.getMsgCount(), eventList.size(), "Incorrect number of messages consumed!"); int counter = 0; for (Event currentEvent : agentServer.getPreservedEventList()) { currentEvent.setTimeStamp(0); Assert.assertEquals(currentEvent.toString(), eventList.get(counter).toString(), "Mapping is incorrect!"); counter++; } } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }
Example 16
Source File: MQTTTestCase.java From product-cep with Apache License 2.0 | 4 votes |
@Test(groups = {"wso2.cep"}, description = "Testing mqtt receiver with JSON formatted event") public void MQTTJSONTestScenario() throws Exception { final int messageCount = 3; String samplePath = "inputflows" + File.separator + "sample0016"; int startESCount = eventStreamManagerAdminServiceClient.getEventStreamCount(); int startERCount = eventReceiverAdminServiceClient.getActiveEventReceiverCount(); int startEPCount = eventPublisherAdminServiceClient.getActiveEventPublisherCount(); // Add StreamDefinition. String streamDefinitionAsString = getJSONArtifactConfiguration(samplePath, "org.wso2.event.sensor.stream_1.0.0.json"); eventStreamManagerAdminServiceClient.addEventStreamAsString(streamDefinitionAsString); Assert.assertEquals(eventStreamManagerAdminServiceClient.getEventStreamCount(), startESCount + 1); // Add MQTT JSON EventReceiver without mapping. String eventReceiverConfig = getXMLArtifactConfiguration(samplePath, "mqttEventReceiver.xml"); eventReceiverAdminServiceClient.addEventReceiverConfiguration(eventReceiverConfig); Assert.assertEquals(eventReceiverAdminServiceClient.getActiveEventReceiverCount(), startERCount + 1); // Add Wso2event EventPublisher. String eventPublisherConfig2 = getXMLArtifactConfiguration(samplePath, "wso2EventPublisher.xml"); eventPublisherAdminServiceClient.addEventPublisherConfiguration(eventPublisherConfig2); Assert.assertEquals(eventPublisherAdminServiceClient.getActiveEventPublisherCount(), startEPCount + 1); // The data-bridge receiver Wso2EventServer agentServer = new Wso2EventServer(samplePath, CEPIntegrationTestConstants.TCP_PORT, true); Thread agentServerThread = new Thread(agentServer); agentServerThread.start(); // Wait till the server to completely start (until Starting polling event receivers & MQTT Connection). Thread.sleep(60000); try { MQTTEventPublisherClient.publish("tcp://localhost:1883", "sensordata", samplePath, "mqttEvents.txt"); // Wait while all stats are published Thread.sleep(10000); List<Event> eventList = new ArrayList<>(); Event event = new Event(); event.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event.setMetaData(new Object[]{4354643l, false, 701, "temperature"}); event.setCorrelationData(new Object[]{4.504343, 20.44345}); event.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event); Event event2 = new Event(); event2.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event2.setMetaData(new Object[]{4354643l, false, 702, "temperature"}); event2.setCorrelationData(new Object[]{4.504343, 20.44345}); event2.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event2); Event event3 = new Event(); event3.setStreamId("org.wso2.event.sensor.stream:1.0.0"); event3.setMetaData(new Object[]{4354643l, false, 703, "temperature"}); event3.setCorrelationData(new Object[]{4.504343, 20.44345}); event3.setPayloadData(new Object[]{2.3f, 4.504343}); eventList.add(event3); Assert.assertEquals(agentServer.getMsgCount(), messageCount, "Incorrect number of messages consumed!"); List<Event> preservedEventList = agentServer.getPreservedEventList(); for (Event aEvent : preservedEventList) { aEvent.setTimeStamp(0); } Assert.assertEquals(preservedEventList, eventList, "Mapping is incorrect!"); eventStreamManagerAdminServiceClient.removeEventStream("org.wso2.event.sensor.stream", "1.0.0"); eventReceiverAdminServiceClient.removeInactiveEventReceiverConfiguration("mqttEventReceiver.xml"); eventPublisherAdminServiceClient.removeInactiveEventPublisherConfiguration("wso2EventPublisher.xml"); } catch (Throwable e) { log.error("Exception thrown: " + e.getMessage(), e); Assert.fail("Exception: " + e.getMessage()); } finally { agentServer.stop(); } }