servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkoeh...@apache.org
Subject svn commit: r678358 - in /servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz: CountDownReceiverComponent.java QuartzComponentTest.java
Date Mon, 21 Jul 2008 06:38:42 GMT
Author: kkoehler
Date: Sun Jul 20 23:38:41 2008
New Revision: 678358

URL: http://svn.apache.org/viewvc?rev=678358&view=rev
Log:
[SM-1366] Strange threading problems running quartz component tests (see https://issues.apache.org/activemq/browse/SM-1366)

Added:
    servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/CountDownReceiverComponent.java
  (with props)
Modified:
    servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/QuartzComponentTest.java

Added: servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/CountDownReceiverComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/CountDownReceiverComponent.java?rev=678358&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/CountDownReceiverComponent.java
(added)
+++ servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/CountDownReceiverComponent.java
Sun Jul 20 23:38:41 2008
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.quartz;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.tck.MessageList;
+import org.apache.servicemix.tck.Receiver;
+
+/**
+ * A simple receiver component which can be configured to
+ * wait for messages before the method getMessageList returns.
+ *
+ * @version $Revision$
+ */
+public class CountDownReceiverComponent extends ComponentSupport implements MessageExchangeListener,
Receiver {
+
+    public static final QName SERVICE = new QName("http://servicemix.org/example/", "countDownReceiver");
+    public static final String ENDPOINT = "countDownReceiver";
+
+    private CountDownLatch countDownLatch;
+    private long timeout;
+    private int messageCount;
+    
+    private MessageList messageList = new MessageList();
+
+    public CountDownReceiverComponent(int messageCount, long milliSecTimeOut) {
+        this(SERVICE, ENDPOINT, messageCount, milliSecTimeOut);
+    }
+    
+    public CountDownReceiverComponent(QName service, String endpoint, int messageCount, long
milliSecTimeOut) {
+        super(service, endpoint);
+        this.countDownLatch = new CountDownLatch(messageCount);
+        this.timeout = milliSecTimeOut;
+        this.messageCount = messageCount;
+    }
+    
+    // MessageExchangeListener interface
+    //-------------------------------------------------------------------------
+    public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+        NormalizedMessage inMessage = getInMessage(exchange);
+        // Copy message to avoid possible closed stream exceptions
+        // when using StreamSource
+        NormalizedMessage copyMessage = exchange.createMessage();
+        getMessageTransformer().transform(exchange, inMessage, copyMessage);
+        messageList.addMessage(copyMessage);
+        done(exchange);
+        if (countDownLatch != null) {
+            countDownLatch.countDown();
+        }
+    }
+
+    // Receiver interface
+    //-------------------------------------------------------------------------
+    public MessageList getMessageList() {
+        if (countDownLatch != null) {
+            try {
+                countDownLatch.await(timeout, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return messageList;
+    }
+    
+    public void reset() {
+        this.countDownLatch = new CountDownLatch(messageCount);
+    }
+    
+}

Propchange: servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/CountDownReceiverComponent.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/QuartzComponentTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/QuartzComponentTest.java?rev=678358&r1=678357&r2=678358&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/QuartzComponentTest.java
(original)
+++ servicemix/components/engines/servicemix-quartz/trunk/src/test/java/org/apache/servicemix/quartz/QuartzComponentTest.java
Sun Jul 20 23:38:41 2008
@@ -21,7 +21,6 @@
 import junit.framework.TestCase;
 
 import org.apache.servicemix.jbi.container.JBIContainer;
-import org.apache.servicemix.tck.ReceiverComponent;
 import org.springframework.scheduling.quartz.SimpleTriggerBean;
 
 public class QuartzComponentTest extends TestCase {
@@ -35,7 +34,7 @@
         QuartzEndpoint endpoint = new QuartzEndpoint();
         endpoint.setService(new QName("quartz"));
         endpoint.setEndpoint("endpoint");
-        endpoint.setTargetService(new QName("receiver"));
+        endpoint.setTargetService(new QName("countDownReceiver"));
         SimpleTriggerBean trigger = new SimpleTriggerBean();
         trigger.setRepeatInterval(100);
         trigger.setName("trigger");
@@ -44,12 +43,11 @@
         quartz.setEndpoints(new QuartzEndpoint[] {endpoint });
         jbi.activateComponent(quartz, "servicemix-quartz");
         
-        ReceiverComponent receiver = new ReceiverComponent(new QName("receiver"), "endpoint");
-        jbi.activateComponent(receiver, "receiver");
+        CountDownReceiverComponent receiver = new CountDownReceiverComponent(new QName("countDownReceiver"),
"endpoint", 1, 3000);
+        jbi.activateComponent(receiver, "countDownReceiver");
         
         jbi.start();
 
-        Thread.sleep(1000);
         assertTrue(receiver.getMessageList().flushMessages().size() > 0);
         
         quartz.stop();
@@ -58,7 +56,8 @@
         assertEquals(0, receiver.getMessageList().flushMessages().size());
         
         quartz.start();
-        Thread.sleep(1000);
+        receiver.reset();
+        
         assertTrue(receiver.getMessageList().flushMessages().size() > 0);
 
         jbi.shutDown();



Mime
View raw message