Repository: stratos Updated Branches: refs/heads/stratos-4.1.x 70eaa362d -> cd614e8bd
Adding Thrift health stat integration test for PCA Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/cd614e8b Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/cd614e8b Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/cd614e8b Branch: refs/heads/stratos-4.1.x Commit: cd614e8bd9c965e90e768f9f1d89b5b751d45bc4 Parents: 70eaa36 Author: Akila Perera <[email protected]> Authored: Wed Sep 16 15:05:35 2015 +0530 Committer: Akila Perera <[email protected]> Committed: Wed Sep 16 15:07:23 2015 +0530 ---------------------------------------------------------------------- .../integration/common/ThriftTestServer.java | 38 ++++++++++++-------- .../integration/tests/AgentStartupTestCase.java | 31 +++++++++++++++- .../tests/PythonAgentIntegrationTest.java | 2 +- 3 files changed, 55 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/cd614e8b/products/python-cartridge-agent/modules/integration/test-common/src/main/java/org/apache/stratos/python/cartridge/agent/integration/common/ThriftTestServer.java ---------------------------------------------------------------------- diff --git a/products/python-cartridge-agent/modules/integration/test-common/src/main/java/org/apache/stratos/python/cartridge/agent/integration/common/ThriftTestServer.java b/products/python-cartridge-agent/modules/integration/test-common/src/main/java/org/apache/stratos/python/cartridge/agent/integration/common/ThriftTestServer.java index 6bbc65a..e75dfa5 100644 --- a/products/python-cartridge-agent/modules/integration/test-common/src/main/java/org/apache/stratos/python/cartridge/agent/integration/common/ThriftTestServer.java +++ b/products/python-cartridge-agent/modules/integration/test-common/src/main/java/org/apache/stratos/python/cartridge/agent/integration/common/ThriftTestServer.java @@ -40,11 +40,12 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; public class ThriftTestServer { - Logger log = Logger.getLogger(ThriftTestServer.class); - ThriftDataReceiver thriftDataReceiver; - InMemoryStreamDefinitionStore streamDefinitionStore; - AtomicInteger numberOfEventsReceived; - RestarterThread restarterThread; + private Logger log = Logger.getLogger(ThriftTestServer.class); + private ThriftDataReceiver thriftDataReceiver; + private InMemoryStreamDefinitionStore streamDefinitionStore; + private AtomicInteger numberOfEventsReceived; + private RestarterThread restarterThread; + private DataBridge databridge; public void startTestServer() throws DataBridgeException, InterruptedException { ThriftTestServer thriftTestServer = new ThriftTestServer(); @@ -76,7 +77,7 @@ public class ThriftTestServer { DataPublisherTestUtil.setKeyStoreParams(); streamDefinitionStore = getStreamDefinitionStore(); numberOfEventsReceived = new AtomicInteger(0); - DataBridge databridge = new DataBridge(new AuthenticationHandler() { + databridge = new DataBridge(new AuthenticationHandler() { @Override public boolean authenticate(String userName, String password) { @@ -110,23 +111,20 @@ public class ThriftTestServer { thriftDataReceiver = new ThriftDataReceiver(receiverPort, databridge); databridge.subscribe(new AgentCallback() { - int totalSize = 0; - - public void definedStream(StreamDefinition streamDefinition, - int tenantId) { - log.info("StreamDefinition " + streamDefinition); + @Override + public void definedStream(StreamDefinition streamDefinition, int tenantId) { + log.info("StreamDefinition defined:" + streamDefinition); } @Override public void removeStream(StreamDefinition streamDefinition, int tenantId) { - log.info("StreamDefinition remove " + streamDefinition); + log.info("StreamDefinition removed: " + streamDefinition); } @Override public void receive(List<Event> eventList, Credentials credentials) { numberOfEventsReceived.addAndGet(eventList.size()); - log.info("Received events : " + numberOfEventsReceived); -// log.info("eventListSize=" + eventList.size() + " eventList " + eventList + " for username " + credentials.getUsername()); + log.info("Number of received events: " + numberOfEventsReceived); } }); @@ -212,4 +210,16 @@ public class ThriftTestServer { } } + + public ThriftDataReceiver getThriftDataReceiver() { + return thriftDataReceiver; + } + + public RestarterThread getRestarterThread() { + return restarterThread; + } + + public DataBridge getDatabridge() { + return databridge; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/cd614e8b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java ---------------------------------------------------------------------- diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java index 5243b43..45044ec 100755 --- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java +++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java @@ -30,6 +30,9 @@ import org.apache.stratos.messaging.listener.instance.status.InstanceActivatedEv import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import org.wso2.carbon.databridge.commons.Credentials; +import org.wso2.carbon.databridge.commons.StreamDefinition; +import org.wso2.carbon.databridge.core.AgentCallback; import java.io.IOException; import java.util.ArrayList; @@ -51,6 +54,7 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { private static final String SERVICE_NAME = "php"; private boolean startupTestCompleted = false; private boolean topologyContextTestCompleted = false; + private boolean thriftTestCompleted = false; private Topology topology = createTestTopology(); public AgentStartupTestCase() throws IOException { @@ -82,6 +86,7 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { "topology context update", groups = {"smoke"}) public void testPythonCartridgeAgent() { startCommunicatorThread(); + subscribeToThriftDatabridge(); Thread startupTestThread = new Thread(new Runnable() { @Override public void run() { @@ -141,13 +146,37 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { } }); - while (!instanceStarted || !instanceActivated || !startupTestCompleted || !topologyContextTestCompleted) { + while (!instanceStarted || !instanceActivated || !startupTestCompleted || !topologyContextTestCompleted || + !thriftTestCompleted) { // wait until the instance activated event is received. // this will assert whether instance got activated within timeout period; no need for explicit assertions sleep(2000); } } + private void subscribeToThriftDatabridge() { + thriftTestServer.getDatabridge().subscribe(new AgentCallback() { + @Override + public void definedStream(StreamDefinition streamDefinition, int tenantId) { + // ignore + } + + @Override + public void removeStream(StreamDefinition streamDefinition, int tenantId) { + // ignore + } + + @Override + public void receive(List<org.wso2.carbon.databridge.commons.Event> eventList, Credentials credentials) { + log.info("Event list size: " + eventList.size()); + log.info("Recent events received: " + eventList); + // if the list contains an event that means PCA was able to successfully publish health stats + if (eventList.size() > 0) { + thriftTestCompleted = true; + } + } + }); + } /** * Create test topology http://git-wip-us.apache.org/repos/asf/stratos/blob/cd614e8b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java ---------------------------------------------------------------------- diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java index f0d94d0..52ee0ad 100644 --- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java +++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java @@ -73,7 +73,7 @@ public class PythonAgentIntegrationTest { protected boolean instanceStarted; protected boolean instanceActivated; protected ByteArrayOutputStreamLocal outputStream; - private ThriftTestServer thriftTestServer; + protected ThriftTestServer thriftTestServer; /** * Setup method for test method testPythonCartridgeAgent
