Github user chamilad commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/236#discussion_r25454950
  
    --- Diff: 
components/org.apache.stratos.python.cartridge.agent/src/test/java/org/apache/stratos/python.cartridge.agent/test/PythonCartridgeAgentTest.java
 ---
    @@ -104,97 +170,118 @@ public static void tearDown() {
                 } catch (IOException ignore) {
                 }
             }
    -    }
     
    -    @Test(timeout = TIMEOUT)
    -    public void testPythonCartridgeAgent() {
    +        try {
    +            log.info("Deleting source checkout folder...");
    +            FileUtils.deleteDirectory(new File(SOURCE_PATH));
    +        } catch (Exception ignore){
     
    -        ExecutorService executorService = 
StratosThreadPool.getExecutorService("TEST_THREAD_POOL", 5);
    -        TopologyEventReceiver topologyEventReceiver = new 
TopologyEventReceiver();
    -        topologyEventReceiver.setExecutorService(executorService);
    -        topologyEventReceiver.execute();
    +        }
     
    -        InstanceStatusEventReceiver instanceStatusEventReceiver = new 
InstanceStatusEventReceiver();
    -        instanceStatusEventReceiver.setExecutorService(executorService);
    -        instanceStatusEventReceiver.execute();
    +        this.instanceStatusEventReceiver.terminate();
    +        this.topologyEventReceiver.terminate();
     
    -        final boolean[] instanceStarted = new boolean[1];
    -        instanceStatusEventReceiver.addEventListener(new 
InstanceStartedEventListener() {
    -            @Override
    -            protected void onEvent(Event event) {
    -                log.info("Instance started event received");
    -                instanceStarted[0] = true;
    -            }
    -        });
    +        this.instanceActivated = false;
    +        this.instanceStarted = false;
    +    }
     
     
    -        final boolean[] instanceActivated = new boolean[1];
    -        instanceStatusEventReceiver.addEventListener(new 
InstanceActivatedEventListener() {
    -            @Override
    -            protected void onEvent(Event event) {
    -                log.info("Instance activated event received");
    -                instanceActivated[0] = true;
    -            }
    +    /**
    +     * This method returns a collection of {@link 
org.apache.stratos.messaging.event.instance.notifier.ArtifactUpdatedEvent}
    +     * objects as parameters to the test
    +     * @return
    +     */
    +    @Parameterized.Parameters
    +    public static Collection getArtifactUpdatedEventsAsParams(){
    +        ArtifactUpdatedEvent publicRepoEvent = 
createTestArtifactUpdatedEvent();
    +
    +        ArtifactUpdatedEvent privateRepoEvent = 
createTestArtifactUpdatedEvent();
    +        
privateRepoEvent.setRepoURL("https://bitbucket.org/testapache2211/testrepo.git";);
    +        privateRepoEvent.setRepoUserName("testapache2211");
    +        privateRepoEvent.setRepoPassword("iF7qT+BKKPE3PGV1TeDsJA==");
    +
    +        ArtifactUpdatedEvent privateRepoEvent2 = 
createTestArtifactUpdatedEvent();
    +        
privateRepoEvent2.setRepoURL("https://testapache2...@bitbucket.org/testapache2211/testrepo.git";);
    +        privateRepoEvent2.setRepoUserName("testapache2211");
    +        privateRepoEvent2.setRepoPassword("iF7qT+BKKPE3PGV1TeDsJA==");
    +
    +        return Arrays.asList(new Object[][]{
    +                {publicRepoEvent, true},
    +                {privateRepoEvent, true},
    +                {privateRepoEvent2, true}
             });
     
    -        // Simulate CEP server socket
    -        startServerSocket(7711);
    +    }
     
    -        String agentPath = setupPythonAgent();
    -        log.info("Starting python cartridge agent...");
    -        ByteArrayOutputStreamLocal outputStream = executeCommand("python " 
+ agentPath + "/agent.py");
    -
    -        List<String> outputLines = new ArrayList<String>();
    -        while (!outputStream.isClosed()) {
    -            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...");
    -                        Topology topology = createTestTopology();
    -                        CompleteTopologyEvent completeTopologyEvent = new 
CompleteTopologyEvent(topology);
    -                        publishEvent(completeTopologyEvent);
    -                        log.info("Complete topology event published");
    -
    -                        sleep(5000);
    -                        // 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
    -                        );
    -                        publishEvent(memberInitializedEvent);
    -                        log.info("Member initialized event published");
    -
    -                        // Simulate server socket
    -                        startServerSocket(9080);
    -                    }
    -                    if (line.contains("Artifact repository found")) {
    -                        // Send artifact updated event
    -                        ArtifactUpdatedEvent artifactUpdatedEvent = new 
ArtifactUpdatedEvent();
    -                        artifactUpdatedEvent.setClusterId(CLUSTER_ID);
    -                        artifactUpdatedEvent.setTenantId(TENANT_ID);
    -                        
artifactUpdatedEvent.setRepoURL("https://bitbucket.org/testapache2211/opentestrepo1.git";);
    -                        String topicName = 
MessagingUtil.getMessageTopicName(artifactUpdatedEvent);
    -                        EventPublisher eventPublisher = 
EventPublisherPool.getPublisher(topicName);
    -                        eventPublisher.publish(artifactUpdatedEvent);
    -                    }
    -                    if (line.contains("Exception in thread") || 
line.contains("ERROR")) {
    -                        //throw new RuntimeException(line);
    +    /**
    +     * Creates an {@link 
org.apache.stratos.messaging.event.instance.notifier.ArtifactUpdatedEvent} 
object with a public
    +     * repository URL
    +     * @return
    +     */
    +    private static ArtifactUpdatedEvent createTestArtifactUpdatedEvent() {
    +        ArtifactUpdatedEvent publicRepoEvent = new ArtifactUpdatedEvent();
    +        publicRepoEvent.setClusterId(CLUSTER_ID);
    +        publicRepoEvent.setTenantId(TENANT_ID);
    +        
publicRepoEvent.setRepoURL("https://bitbucket.org/testapache2211/opentestrepo1.git";);
    +        return publicRepoEvent;
    +    }
    +
    +    @Test(timeout = TIMEOUT)
    +    public void testPythonCartridgeAgent() {
    +        Thread communicatorThread = new Thread(new Runnable() {
    +            @Override
    +            public void run() {
    +                List<String> outputLines = new ArrayList<String>();
    +                while (!outputStream.isClosed()) {
    +                    List<String> newLines = getNewLines(outputLines, 
outputStream.toString());
    +                    if (newLines.size() > 0) {
    +                        for (String line : newLines) {
    +                            if (line.contains("Subscribed to 
'topology/#'")) {
    +                                sleep(1000);
    +                                // Send complete topology event
    +                                log.info("Publishing complete topology 
event...");
    +                                Topology topology = createTestTopology();
    +                                CompleteTopologyEvent 
completeTopologyEvent = new CompleteTopologyEvent(topology);
    +                                publishEvent(completeTopologyEvent);
    +                                log.info("Complete topology event 
published");
    +
    +                                sleep(3000);
    +                                // 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
    +                                );
    +                                publishEvent(memberInitializedEvent);
    +                                log.info("Member initialized event 
published");
    +
    +                                // Simulate server socket
    +                                startServerSocket(9080);
    +                            }
    +                            if (line.contains("Artifact repository 
found")) {
    +                                // Send artifact updated event
    +                                publishEvent(artifactUpdatedEvent);
    +                            }
    +
    +                            if (line.contains("Exception in thread") || 
line.contains("ERROR")) {
    +                                //throw new RuntimeException(line);
    --- End diff --
    
    Hi @prabathabey , yes at the moment this does not serve any purpose. 
However the plan is to check the class of the error thrown and fail the test 
accordingly. This should be commented out. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to