Repository: stratos Updated Branches: refs/heads/stratos-4.1.x 00f624b48 -> 60b801144
http://git-wip-us.apache.org/repos/asf/stratos/blob/60b80114/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/publisher.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/publisher.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/publisher.py index f78f460..0994048 100644 --- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/publisher.py +++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/publisher.py @@ -17,12 +17,12 @@ import paho.mqtt.publish as publish -from modules.event.instance.status.events import * -from modules.util.log import * -from modules.util import cartridgeagentutils -import healthstats import constants +import healthstats from config import Config +from modules.event.instance.status.events import * +from modules.util import cartridgeagentutils +from modules.util.log import * log = LogFactory().get_log(__name__) publishers = {} @@ -183,6 +183,20 @@ def publish_instance_ready_to_shutdown_event(): log.warn("Instance already in a ReadyToShutDown event...") +def publish_complete_topology_request_event(): + complete_topology_request_event = CompleteTopologyRequestEvent() + publisher = get_publisher(constants.INITIALIZER_TOPIC + constants.COMPLETE_TOPOLOGY_REQUEST_EVENT) + publisher.publish(complete_topology_request_event) + log.info("Complete topology request event published") + + +def publish_complete_tenant_request_event(): + complete_tenant_request_event = CompleteTenantRequestEvent() + publisher = get_publisher(constants.INITIALIZER_TOPIC + constants.COMPLETE_TENANT_REQUEST_EVENT) + publisher.publish(complete_tenant_request_event) + log.info("Complete tenant request event published") + + def get_publisher(topic): if topic not in publishers: publishers[topic] = EventPublisher(topic) http://git-wip-us.apache.org/repos/asf/stratos/blob/60b80114/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 8f80013..f0a70d4 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 @@ -22,10 +22,14 @@ package org.apache.stratos.python.cartridge.agent.integration.tests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.common.domain.LoadBalancingIPType; +import org.apache.stratos.messaging.domain.tenant.Tenant; import org.apache.stratos.messaging.domain.topology.*; import org.apache.stratos.messaging.event.Event; +import org.apache.stratos.messaging.event.tenant.CompleteTenantEvent; import org.apache.stratos.messaging.event.topology.CompleteTopologyEvent; import org.apache.stratos.messaging.event.topology.MemberInitializedEvent; +import org.apache.stratos.messaging.listener.initializer.CompleteTenantRequestEventListener; +import org.apache.stratos.messaging.listener.initializer.CompleteTopologyRequestEventListener; import org.apache.stratos.messaging.listener.instance.status.InstanceActivatedEventListener; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -55,6 +59,7 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { private static final String SERVICE_NAME = "php"; private boolean startupTestCompleted = false; private boolean topologyContextTestCompleted = false; + private boolean completeTenantInitialized = false; private boolean thriftTestCompleted = false; private Topology topology = createTestTopology(); @@ -74,7 +79,6 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { startServerSocket(8080); } - /** * TearDown method for test method testPythonCartridgeAgent */ @@ -83,8 +87,9 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { tearDown(); } - @Test(timeOut = STARTUP_TIMEOUT, description = "Test PCA initialization, activation, health stat publishing and " + - "topology context update", groups = {"smoke"}) + @Test(timeOut = STARTUP_TIMEOUT, + description = "Test PCA initialization, activation, health stat publishing and " + "topology context update", + groups = { "smoke" }) public void testPythonCartridgeAgent() { startCommunicatorThread(); subscribeToThriftDatabridge(); @@ -99,24 +104,6 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { List<String> newLines = getNewLines(outputLines, outputStream.toString()); if (newLines.size() > 0) { for (String line : newLines) { - if (line.contains("Subscribed to 'topology/#'")) { - sleep(2000); - // Send complete topology event - log.info("Publishing complete topology event..."); - CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology); - publishEvent(completeTopologyEvent); - log.info("Complete topology event published"); - - // Publish member initialized event - log.info("Publishing member initialized event..."); - MemberInitializedEvent memberInitializedEvent = new MemberInitializedEvent( - SERVICE_NAME, CLUSTER_ID, CLUSTER_INSTANCE_ID, MEMBER_ID, NETWORK_PARTITION_ID, - PARTITION_ID, INSTANCE_ID - ); - publishEvent(memberInitializedEvent); - log.info("Member initialized event published"); - } - if (line.contains("Published event to thrift stream")) { startupTestCompleted = true; } @@ -125,6 +112,11 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { if (line.contains("Topology context update test passed!")) { topologyContextTestCompleted = true; } + + // assert complete tenant initialization + if (line.contains("Tenant context updated with")){ + completeTenantInitialized = true; + } } } sleep(1000); @@ -134,6 +126,35 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { startupTestThread.start(); + initializerEventReceiver.addEventListener(new CompleteTopologyRequestEventListener() { + @Override + protected void onEvent(Event event) { + // Send complete topology event + log.info("CompleteTopologyRequestEvent received. Publishing complete topology event..."); + CompleteTopologyEvent completeTopologyEvent = new CompleteTopologyEvent(topology); + publishEvent(completeTopologyEvent); + log.info("Complete topology event published"); + + // Publish member initialized event + log.info("Publishing member initialized event..."); + MemberInitializedEvent memberInitializedEvent = new MemberInitializedEvent(SERVICE_NAME, CLUSTER_ID, + CLUSTER_INSTANCE_ID, MEMBER_ID, NETWORK_PARTITION_ID, PARTITION_ID, INSTANCE_ID); + publishEvent(memberInitializedEvent); + log.info("Member initialized event published"); + } + }); + + initializerEventReceiver.addEventListener(new CompleteTenantRequestEventListener() { + @Override + protected void onEvent(Event event) { + // Send complete tenant event + log.info("CompleteTenantRequestEvent received. Publishing complete tenant event..."); + CompleteTenantEvent completeTenantEvent = new CompleteTenantEvent(createTestTenantList()); + publishEvent(completeTenantEvent); + log.info("Complete tenant event published"); + } + }); + instanceStatusEventReceiver.addEventListener(new InstanceActivatedEventListener() { @Override protected void onEvent(Event event) { @@ -148,7 +169,7 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { }); while (!instanceStarted || !instanceActivated || !startupTestCompleted || !topologyContextTestCompleted || - !thriftTestCompleted) { + !thriftTestCompleted || !completeTenantInitialized) { // 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); @@ -180,6 +201,19 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { } /** + * Create test tenant list + * + * @return List of tenant objects with mock information + */ + private List<Tenant> createTestTenantList() { + List<Tenant> tenantList = new ArrayList<>(); + tenantList.add(new Tenant(1, "test.one.domain")); + tenantList.add(new Tenant(2, "test.two.domain")); + tenantList.add(new Tenant(3, "test.three.domain")); + return tenantList; + } + + /** * Create test topology * * @return Topology object with mock information @@ -193,9 +227,8 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest { AUTOSCALING_POLICY_NAME, APP_ID); service.addCluster(cluster); - Member member = new Member(service.getServiceName(), cluster.getClusterId(), MEMBER_ID, - CLUSTER_INSTANCE_ID, NETWORK_PARTITION_ID, PARTITION_ID, LoadBalancingIPType.Private, - System.currentTimeMillis()); + Member member = new Member(service.getServiceName(), cluster.getClusterId(), MEMBER_ID, CLUSTER_INSTANCE_ID, + NETWORK_PARTITION_ID, PARTITION_ID, LoadBalancingIPType.Private, System.currentTimeMillis()); member.setDefaultPrivateIP("10.0.0.1"); member.setDefaultPublicIP("20.0.0.1"); http://git-wip-us.apache.org/repos/asf/stratos/blob/60b80114/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 66b9290..d441c1e 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 @@ -33,6 +33,7 @@ import org.apache.stratos.messaging.broker.publish.EventPublisherPool; import org.apache.stratos.messaging.event.Event; import org.apache.stratos.messaging.listener.instance.status.InstanceActivatedEventListener; import org.apache.stratos.messaging.listener.instance.status.InstanceStartedEventListener; +import org.apache.stratos.messaging.message.receiver.initializer.InitializerEventReceiver; import org.apache.stratos.messaging.message.receiver.instance.status.InstanceStatusEventReceiver; import org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver; import org.apache.stratos.messaging.util.MessagingUtil; @@ -72,6 +73,7 @@ public class PythonAgentIntegrationTest { protected boolean eventReceiverInitiated = false; protected TopologyEventReceiver topologyEventReceiver; protected InstanceStatusEventReceiver instanceStatusEventReceiver; + protected InitializerEventReceiver initializerEventReceiver; protected boolean instanceStarted; protected boolean instanceActivated; protected ByteArrayOutputStreamLocal outputStream; @@ -112,14 +114,17 @@ public class PythonAgentIntegrationTest { } }); + initializerEventReceiver = new InitializerEventReceiver(); + initializerEventReceiver.setExecutorService(executorService); + initializerEventReceiver.execute(); + this.eventReceiverInitiated = true; } // Start CEP Thrift test server thriftTestServer = new ThriftTestServer(); - File file = - new File(getResourcesPath() + PATH_SEP + "common" + PATH_SEP + "stratos-health-stream-def.json"); + File file = new File(getResourcesPath() + PATH_SEP + "common" + PATH_SEP + "stratos-health-stream-def.json"); FileInputStream fis = new FileInputStream(file); byte[] data = new byte[(int) file.length()]; fis.read(data); @@ -139,7 +144,6 @@ public class PythonAgentIntegrationTest { this.outputStream = executeCommand("python " + agentPath + PATH_SEP + "agent.py", timeout); } - protected void tearDown() { tearDown(null); } @@ -155,8 +159,7 @@ public class PythonAgentIntegrationTest { log.info("Terminating process: " + commandText); executor.setExitValue(0); executor.getWatchdog().destroyProcess(); - } - catch (Exception ignore) { + } catch (Exception ignore) { } } // wait until everything cleans up to avoid connection errors @@ -165,36 +168,34 @@ public class PythonAgentIntegrationTest { try { log.info("Stopping socket server: " + serverSocket.getLocalSocketAddress()); serverSocket.close(); - } - catch (IOException ignore) { + } catch (IOException ignore) { } } try { if (thriftTestServer != null) { thriftTestServer.stop(); } - } - catch (Exception ignore) { + } catch (Exception ignore) { } if (sourcePath != null) { try { log.info("Deleting source checkout folder..."); FileUtils.deleteDirectory(new File(sourcePath)); - } - catch (Exception ignore) { + } catch (Exception ignore) { } } + log.info("Terminating event receivers..."); this.instanceStatusEventReceiver.terminate(); this.topologyEventReceiver.terminate(); + this.initializerEventReceiver.terminate(); this.instanceActivated = false; this.instanceStarted = false; try { broker.stop(); broker = null; - } - catch (Exception ignore) { + } catch (Exception ignore) { } // TODO: use thread synchronization and assert all connections are properly closed // leave some room to clear up active connections @@ -203,8 +204,7 @@ public class PythonAgentIntegrationTest { public PythonAgentIntegrationTest() throws IOException { integrationProperties - .load(PythonAgentIntegrationTest.class - .getResourceAsStream(PATH_SEP + "integration-test.properties")); + .load(PythonAgentIntegrationTest.class.getResourceAsStream(PATH_SEP + "integration-test.properties")); distributionName = integrationProperties.getProperty(DISTRIBUTION_NAME); amqpBindAddress = integrationProperties.getProperty(ACTIVEMQ_AMQP_BIND_ADDRESS); mqttBindAddress = integrationProperties.getProperty(ACTIVEMQ_MQTT_BIND_ADDRESS); @@ -223,7 +223,7 @@ public class PythonAgentIntegrationTest { AuthenticationUser authenticationUser = new AuthenticationUser("system", "manager", "users,admins"); List<AuthenticationUser> authUserList = new ArrayList<>(); authUserList.add(authenticationUser); - broker.setPlugins(new BrokerPlugin[]{new SimpleAuthenticationPlugin(authUserList)}); + broker.setPlugins(new BrokerPlugin[] { new SimpleAuthenticationPlugin(authUserList) }); broker.setBrokerName("testBroker"); broker.setDataDirectory( PythonAgentIntegrationTest.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".." + PATH_SEP + @@ -244,8 +244,7 @@ public class PythonAgentIntegrationTest { if (line.contains("Exception in thread") || line.contains("ERROR")) { try { throw new RuntimeException(line); - } - catch (Exception e) { + } catch (Exception e) { log.error("ERROR found in PCA log", e); } } @@ -284,8 +283,7 @@ public class PythonAgentIntegrationTest { log.info("Message received for [port] " + port + ", [message] " + output); } } - } - catch (IOException e) { + } catch (IOException e) { String message = "Could not start server socket: [port] " + port; log.error(message, e); throw new RuntimeException(message, e); @@ -300,7 +298,6 @@ public class PythonAgentIntegrationTest { ".." + PATH_SEP + "src" + PATH_SEP + "test" + PATH_SEP + "resources" + PATH_SEP + "common"; } - public static String getResourcesPath() { return PythonAgentIntegrationTest.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".." + PATH_SEP + ".." + PATH_SEP + "src" + PATH_SEP + "test" + PATH_SEP + "resources"; @@ -320,13 +317,12 @@ public class PythonAgentIntegrationTest { try { log.info("Setting up python cartridge agent..."); - String srcAgentPath = PythonAgentIntegrationTest.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".." + PATH_SEP + ".." + PATH_SEP + ".." + PATH_SEP + ".." + PATH_SEP + "distribution" + PATH_SEP + "target" + PATH_SEP + distributionName + ".zip"; - String unzipDestPath = - PythonAgentIntegrationTest.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".." + PATH_SEP + - PYTHON_AGENT_DIR_NAME + PATH_SEP; + String unzipDestPath = PythonAgentIntegrationTest.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".." + + PATH_SEP + + PYTHON_AGENT_DIR_NAME + PATH_SEP; //FileUtils.copyFile(new File(srcAgentPath), new File(destAgentPath)); unzip(srcAgentPath, unzipDestPath); String destAgentPath = PythonAgentIntegrationTest.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".." + @@ -370,8 +366,7 @@ public class PythonAgentIntegrationTest { log.info("Python cartridge agent setup completed"); return destAgentPath; - } - catch (Exception e) { + } catch (Exception e) { String message = "Could not copy cartridge agent distribution"; log.error(message, e); throw new RuntimeException(message, e); @@ -442,8 +437,7 @@ public class PythonAgentIntegrationTest { }); executorList.put(commandText, exec); return outputStream; - } - catch (Exception e) { + } catch (Exception e) { log.error(outputStream.toString(), e); throw new RuntimeException(e); } @@ -457,8 +451,7 @@ public class PythonAgentIntegrationTest { protected void sleep(long time) { try { Thread.sleep(time); - } - catch (InterruptedException ignore) { + } catch (InterruptedException ignore) { } } @@ -495,7 +488,6 @@ public class PythonAgentIntegrationTest { eventPublisher.publish(event); } - /** * Implements ByteArrayOutputStream.isClosed() method */ http://git-wip-us.apache.org/repos/asf/stratos/blob/60b80114/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java index 721a5c6..e4650e4 100644 --- a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java +++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java @@ -35,6 +35,10 @@ import org.apache.stratos.messaging.listener.application.*; import org.apache.stratos.messaging.listener.topology.*; import org.apache.stratos.messaging.message.receiver.application.ApplicationManager; import org.apache.stratos.messaging.message.receiver.application.ApplicationsEventReceiver; +import org.apache.stratos.messaging.message.receiver.application.signup.ApplicationSignUpEventReceiver; +import org.apache.stratos.messaging.message.receiver.application.signup.ApplicationSignUpManager; +import org.apache.stratos.messaging.message.receiver.tenant.TenantEventReceiver; +import org.apache.stratos.messaging.message.receiver.tenant.TenantManager; import org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver; import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; import org.apache.stratos.mock.iaas.client.MockIaasApiClient; @@ -55,12 +59,18 @@ public class TopologyHandler { public static final int APPLICATION_ACTIVATION_TIMEOUT = 500000; public static final int APPLICATION_UNDEPLOYMENT_TIMEOUT = 500000; public static final int MEMBER_TERMINATION_TIMEOUT = 500000; - public static final int APPLICATION_TOPOLOGY_TIMEOUT = 120000; + public static final int APPLICATION_INIT_TIMEOUT = 20000; + public static final int TENANT_INIT_TIMEOUT = 20000; + public static final int APPLICATION_SIGNUP_INIT_TIMEOUT = 20000; + public static final int TOPOLOGY_INIT_TIMEOUT = 20000; public static final String APPLICATION_STATUS_CREATED = "Created"; public static final String APPLICATION_STATUS_UNDEPLOYING = "Undeploying"; private ApplicationsEventReceiver applicationsEventReceiver; private TopologyEventReceiver topologyEventReceiver; + private TenantEventReceiver tenantEventReceiver; + private ApplicationSignUpEventReceiver applicationSignUpEventReceiver; public static TopologyHandler topologyHandler; + private ExecutorService executorService = StratosThreadPool.getExecutorService("stratos.integration.test.pool", 10); private Map<String, Long> terminatedMembers = new ConcurrentHashMap<String, Long>(); private Map<String, Long> terminatingMembers = new ConcurrentHashMap<String, Long>(); private Map<String, Long> createdMembers = new ConcurrentHashMap<String, Long>(); @@ -70,12 +80,28 @@ public class TopologyHandler { private TopologyHandler() { initializeApplicationEventReceiver(); initializeTopologyEventReceiver(); + initializeTenantEventReceiver(); + initializeApplicationSignUpEventReceiver(); assertApplicationTopologyInitialized(); assertTopologyInitialized(); + assertTenantInitialized(); + assertApplicationSignUpInitialized(); addTopologyEventListeners(); addApplicationEventListeners(); } + private void initializeApplicationSignUpEventReceiver() { + applicationSignUpEventReceiver = new ApplicationSignUpEventReceiver(); + applicationSignUpEventReceiver.setExecutorService(executorService); + applicationSignUpEventReceiver.execute(); + } + + private void initializeTenantEventReceiver() { + tenantEventReceiver = new TenantEventReceiver(); + tenantEventReceiver.setExecutorService(executorService); + tenantEventReceiver.execute(); + } + public static TopologyHandler getInstance() { if (topologyHandler == null) { synchronized (TopologyHandler.class) { @@ -91,30 +117,25 @@ public class TopologyHandler { * Initialize application event receiver */ private void initializeApplicationEventReceiver() { - if (applicationsEventReceiver == null) { - applicationsEventReceiver = new ApplicationsEventReceiver(); - ExecutorService executorService = StratosThreadPool.getExecutorService("STRATOS_TEST_SERVER", 1); - applicationsEventReceiver.setExecutorService(executorService); - applicationsEventReceiver.execute(); - } + applicationsEventReceiver = new ApplicationsEventReceiver(); + applicationsEventReceiver.setExecutorService(executorService); + applicationsEventReceiver.execute(); } /** * Initialize Topology event receiver */ private void initializeTopologyEventReceiver() { - if (topologyEventReceiver == null) { - topologyEventReceiver = new TopologyEventReceiver(); - ExecutorService executorService = StratosThreadPool.getExecutorService("STRATOS_TEST_SERVER1", 1); - topologyEventReceiver.setExecutorService(executorService); - topologyEventReceiver.execute(); - } + topologyEventReceiver = new TopologyEventReceiver(); + topologyEventReceiver.setExecutorService(executorService); + topologyEventReceiver.execute(); } /** * Assert application Topology initialization */ private void assertApplicationTopologyInitialized() { + log.info(String.format("Asserting application topology initialization within %d ms", APPLICATION_INIT_TIMEOUT)); long startTime = System.currentTimeMillis(); boolean applicationTopologyInitialized = ApplicationManager.getApplications().isInitialized(); while (!applicationTopologyInitialized) { @@ -123,18 +144,24 @@ public class TopologyHandler { } catch (InterruptedException ignore) { } applicationTopologyInitialized = ApplicationManager.getApplications().isInitialized(); - if ((System.currentTimeMillis() - startTime) > APPLICATION_TOPOLOGY_TIMEOUT) { + if ((System.currentTimeMillis() - startTime) > APPLICATION_INIT_TIMEOUT) { break; } } - assertEquals(String.format("Application Topology didn't get initialized "), applicationTopologyInitialized, - true); + if (applicationTopologyInitialized) { + log.info(String.format("Application topology initialized under %d ms", + (System.currentTimeMillis() - startTime))); + } + assertEquals( + String.format("Application topology didn't get initialized within %d ms", APPLICATION_INIT_TIMEOUT), + applicationTopologyInitialized, true); } /** * Assert Topology initialization */ private void assertTopologyInitialized() { + log.info(String.format("Asserting topology initialization within %d ms", TOPOLOGY_INIT_TIMEOUT)); long startTime = System.currentTimeMillis(); boolean topologyInitialized = TopologyManager.getTopology().isInitialized(); while (!topologyInitialized) { @@ -143,11 +170,59 @@ public class TopologyHandler { } catch (InterruptedException ignore) { } topologyInitialized = TopologyManager.getTopology().isInitialized(); - if ((System.currentTimeMillis() - startTime) > APPLICATION_TOPOLOGY_TIMEOUT) { + if ((System.currentTimeMillis() - startTime) > TOPOLOGY_INIT_TIMEOUT) { break; } } - assertEquals(String.format("Topology didn't get initialized "), topologyInitialized, true); + if (topologyInitialized) { + log.info(String.format("Topology initialized under %d ms", (System.currentTimeMillis() - startTime))); + } + assertEquals(String.format("Topology didn't get initialized within %d ms", TOPOLOGY_INIT_TIMEOUT), + topologyInitialized, true); + } + + private void assertTenantInitialized() { + log.info(String.format("Asserting tenant model initialization within %d ms", TENANT_INIT_TIMEOUT)); + long startTime = System.currentTimeMillis(); + boolean tenantInitialized = TenantManager.getInstance().isInitialized(); + while (!tenantInitialized) { + try { + Thread.sleep(1000); + } catch (InterruptedException ignore) { + } + tenantInitialized = TenantManager.getInstance().isInitialized(); + if ((System.currentTimeMillis() - startTime) > TENANT_INIT_TIMEOUT) { + break; + } + } + if (tenantInitialized) { + log.info(String.format("Tenant model initialized under %d ms", (System.currentTimeMillis() - startTime))); + } + assertEquals(String.format("Tenant model didn't get initialized within %d ms", TENANT_INIT_TIMEOUT), + tenantInitialized, true); + } + + private void assertApplicationSignUpInitialized() { + log.info(String.format("Asserting application signup initialization within %d ms", + APPLICATION_SIGNUP_INIT_TIMEOUT)); + long startTime = System.currentTimeMillis(); + boolean applicationSignUpInitialized = ApplicationSignUpManager.getInstance().isInitialized(); + while (!applicationSignUpInitialized) { + try { + Thread.sleep(1000); + } catch (InterruptedException ignore) { + } + applicationSignUpInitialized = ApplicationSignUpManager.getInstance().isInitialized(); + if ((System.currentTimeMillis() - startTime) > APPLICATION_SIGNUP_INIT_TIMEOUT) { + break; + } + } + if (applicationSignUpInitialized) { + log.info(String.format("Application signup initialized under %d ms", + (System.currentTimeMillis() - startTime))); + } + assertEquals(String.format("Application signup didn't get initialized within %d ms", + APPLICATION_SIGNUP_INIT_TIMEOUT), applicationSignUpInitialized, true); } /** http://git-wip-us.apache.org/repos/asf/stratos/blob/60b80114/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties b/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties index 6fc6f45..b99dd63 100644 --- a/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties +++ b/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties @@ -59,7 +59,7 @@ log4j.logger.org.apache.stratos.cloud.controller=DEBUG log4j.logger.org.wso2.andes.client=ERROR # Autoscaler rule logs log4j.logger.org.apache.stratos.autoscaler.rule.RuleLog=DEBUG -log4j.logger.org.apache.stratos.cloud.controller.messaging.topology.TopologyManager=INFO +log4j.logger.org.apache.stratos.cloud.controller.messaging.topology.TopologyHolder=INFO log4j.logger.org.apache.stratos.mock.iaas.client=DEBUG log4j.logger.org.apache.stratos.mock.iaas.services=DEBUG log4j.logger.org.apache.stratos.metadata.service=DEBUG
