geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r344061 - in /geronimo/gbuild/trunk/src: main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java
Date Mon, 14 Nov 2005 06:43:19 GMT
Author: dblevins
Date: Sun Nov 13 22:43:16 2005
New Revision: 344061

URL: http://svn.apache.org/viewcvs?rev=344061&view=rev
Log:
Unit test that shoves 12 builds onto the queue and checks the result queue for 12 responses.
Runs from idea, but I have it commented out at the moment as I seem to be missing one class
from the pom

Modified:
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java
    geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java

Modified: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java?rev=344061&r1=344060&r2=344061&view=diff
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java
(original)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgent.java
Sun Nov 13 22:43:16 2005
@@ -113,7 +113,6 @@
 
     public void run() {
         try {
-            init();
             run = true;
 
             Connection connection = null;
@@ -134,9 +133,13 @@
 
             while (run) {
                 // Wait for a message
-                Message message = buildConsumer.receive();
+                Message message = buildConsumer.receive(1000);
 
-                if (message instanceof ObjectMessage) {
+                if (message == null){
+
+                    continue;
+
+                } else if (message instanceof ObjectMessage) {
 
                     ObjectMessage objectMessage = (ObjectMessage) message;
 
@@ -146,6 +149,8 @@
 
                     ThreadContextContinuumStore.setStore(store);
 
+                    init();
+
                     int projectId = getProjectId(mapMessage);
 
                     int buildDefinitionId = getBuildDefinitionId(mapMessage);
@@ -221,53 +226,53 @@
         return connection;
     }
 
-    private void setAdminAddress(Map results) throws JMSException {
+    public void setAdminAddress(Map results) throws JMSException {
         results.put(KEY_ADMIN_ADDRESS, adminAddress);
     }
 
-    private void setContributor(Map results) throws JMSException {
+    public void setContributor(Map results) throws JMSException {
         results.put(KEY_CONTRIBUTOR, contributor);
     }
 
-    private void setHostInformation(Map results) throws UnknownHostException, JMSException
{
+    public static void setHostInformation(Map results) throws UnknownHostException, JMSException
{
         InetAddress localHost = InetAddress.getLocalHost();
         results.put(KEY_HOST_NAME, localHost.getHostName());
         results.put(KEY_HOST_ADDRESS, localHost.getHostAddress());
     }
 
-    private void setSystemProperty(Map results, String name) throws JMSException {
+    public static void setSystemProperty(Map results, String name) throws JMSException {
         results.put(name, System.getProperty(name));
     }
 
-    private void setStore(Map results, ContinuumStore store) throws JMSException {
+    public static void setStore(Map results, ContinuumStore store) throws JMSException {
         results.put(KEY_STORE, store);
     }
 
-    private void setBuildDefinitionId(Map results, int buildDefinitionId) throws JMSException
{
+    public static void setBuildDefinitionId(Map results, int buildDefinitionId) throws JMSException
{
         results.put(KEY_BUILD_DEFINITION_ID, new Integer(buildDefinitionId));
     }
 
-    private void setTrigger(Map results, int trigger) throws JMSException {
+    public static void setTrigger(Map results, int trigger) throws JMSException {
         results.put(KEY_TRIGGER, new Integer(trigger));
     }
 
-    private void setProjectId(Map results, int projectId) throws JMSException {
+    public static void setProjectId(Map results, int projectId) throws JMSException {
         results.put(KEY_PROJECT_ID, new Integer(projectId));
     }
 
-    private int getTrigger(Map mapMessage) throws JMSException {
+    public static int getTrigger(Map mapMessage) throws JMSException {
         return ((Integer)mapMessage.get(KEY_TRIGGER)).intValue();
     }
 
-    private int getBuildDefinitionId(Map mapMessage) throws JMSException {
+    public static int getBuildDefinitionId(Map mapMessage) throws JMSException {
         return ((Integer)mapMessage.get(KEY_BUILD_DEFINITION_ID)).intValue();
     }
 
-    private int getProjectId(Map mapMessage) throws JMSException {
+    public static int getProjectId(Map mapMessage) throws JMSException {
         return ((Integer)mapMessage.get(KEY_PROJECT_ID)).intValue();
     }
 
-    private ContinuumStore getContinuumStore(Map mapMessage) throws JMSException {
+    public static ContinuumStore getContinuumStore(Map mapMessage) throws JMSException {
         return (ContinuumStore) mapMessage.get(KEY_STORE);
     }
 

Modified: geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java?rev=344061&r1=344060&r2=344061&view=diff
==============================================================================
--- geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java
(original)
+++ geronimo/gbuild/trunk/src/test/java/org/apache/geronimo/gbuild/agent/ContinuumBuildAgentTest.java
Sun Nov 13 22:43:16 2005
@@ -10,15 +10,27 @@
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.execution.shell.ShellBuildExecutor;
 import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.apache.maven.continuum.store.ContinuumStore;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.embed.Embedder;
+import org.activemq.ActiveMQConnectionFactory;
 
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.Destination;
+import javax.jms.MessageProducer;
+import javax.jms.DeliveryMode;
+import javax.jms.Topic;
+import javax.jms.Queue;
+import javax.jms.MessageConsumer;
+import javax.jms.ObjectMessage;
 import java.io.File;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 public class ContinuumBuildAgentTest extends TestCase {
-    ContinuumBuildAgent continuumBuildAgent;
 
     private CVS cvs;
     private File shellScript;
@@ -76,7 +88,114 @@
         assertNotNull("buildResult",buildResult);
         assertEquals("buildResult.getState",ContinuumProjectState.OK, buildResult.getState());
         assertEquals("project.getState",ContinuumProjectState.OK, project.getState());
+
+        embedder.stop();
+        ThreadContextContinuumStore.setStore(null);
+    }
+
+
+    public static class TestBroker implements Runnable {
+        private final String[] args;
+
+        public TestBroker(String[] args) {
+            this.args = args;
+        }
+
+        public void run() {
+            org.activemq.broker.impl.Main.main(args);
+        }
+
+        public static void main(String[] args) {
+            org.apache.log4j.BasicConfigurator.configure();
+            new TestBroker(args).run();
+        }
     }
+
+    // need to throw in a Broker
+    public void _testBuildQueue() throws Exception {
+
+        Thread broker = new Thread(new TestBroker(new String[]{}));
+        broker.setDaemon(true);
+        broker.start();
+        Thread.sleep(5000);
+
+        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
+        Connection connection = connectionFactory.createConnection();
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Queue buildQueue = session.createQueue("BUILD.TASKS");
+        MessageProducer producer = session.createProducer(buildQueue);
+        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+        MapContinuumStore store = new MapContinuumStore();
+
+        Project project = new Project();
+        project.setId(12);
+        project.setScmUrl("scm|cvs|local|" + cvs.getCvsroot().getAbsolutePath() + "|shell");
+        project.setName("Shell Project");
+        project.setVersion("3.0");
+        project.setExecutorId(ShellBuildExecutor.ID);
+        project.setState(ContinuumProjectState.OK);
+        store.updateProject(project);
+
+        String[] goals = new String[]{"one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "twelve"};
+
+        for (int i = 0; i < goals.length; i++) {
+            String goal = goals[i];
+            BuildDefinition bd = new BuildDefinition();
+            bd.setId(i);
+            bd.setBuildFile(shellScript.getAbsolutePath());
+            bd.setArguments(goal);
+            project.addBuildDefinition(bd);
+            store.storeBuildDefinition(bd);
+
+            HashMap map = new HashMap();
+
+            ContinuumBuildAgent.setStore(map, store);
+            ContinuumBuildAgent.setProjectId(map, project.getId());
+            ContinuumBuildAgent.setBuildDefinitionId(map, bd.getId());
+            ContinuumBuildAgent.setTrigger(map, 0);
+
+            producer.send(session.createObjectMessage(map));
+        }
+
+        Topic resultsTopic = session.createTopic("BUILD.RESULTS");
+        MessageConsumer resultsConsumer = session.createConsumer(resultsTopic);
+
+        Embedder embedder = new Embedder();
+        embedder.start();
+
+        ContinuumBuildAgent buildAgent = (ContinuumBuildAgent) embedder.lookup(BuildAgent.ROLE);
+        Thread agentThread = new Thread(buildAgent);
+        agentThread.setDaemon(false);
+        agentThread.start();
+
+        // Consume twelve responses
+        for (int i = 0; i < goals.length; i++) {
+            ObjectMessage objectMessage = (ObjectMessage) resultsConsumer.receive();
+            Map results = (Map) objectMessage.getObject();
+            ContinuumStore store2 = ContinuumBuildAgent.getContinuumStore(results);
+
+            int buildDefinitionId = ContinuumBuildAgent.getBuildDefinitionId(results);
+            int projectId = ContinuumBuildAgent.getProjectId(results);
+            Project project2 = store2.getProject(projectId);
+            int latestBuildId = project2.getLatestBuildId();
+            BuildResult buildResult = store2.getBuildResult(latestBuildId);
+
+            System.out.println("[RESULT] "+ project2.getName() +" : "+goals[buildDefinitionId]+"
: "+buildResult.getBuildNumber());
+
+            assertNotNull("buildResult",buildResult);
+            assertEquals("buildResult.getState", ContinuumProjectState.OK, buildResult.getState());
+            assertEquals("project.getState", ContinuumProjectState.OK, project.getState());
+        }
+
+
+        buildAgent.stop();
+
+        session.close();
+        connection.close();
+    }
+
 
     public static void deleteAndCreateDirectory(File directory)
             throws IOException {



Mime
View raw message