Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6D3CB178D0 for ; Wed, 3 Jun 2015 00:14:25 +0000 (UTC) Received: (qmail 51039 invoked by uid 500); 2 Jun 2015 21:27:44 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 51003 invoked by uid 500); 2 Jun 2015 21:27:44 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 50993 invoked by uid 99); 2 Jun 2015 21:27:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jun 2015 21:27:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3F1F8DFF7B; Tue, 2 Jun 2015 21:27:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tabish@apache.org To: commits@activemq.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: activemq git commit: Adds a STOMP based test to cover some inactivity monitor usage over all four transports. Date: Tue, 2 Jun 2015 21:27:44 +0000 (UTC) Repository: activemq Updated Branches: refs/heads/master f37b005ac -> 2d7280f33 Adds a STOMP based test to cover some inactivity monitor usage over all four transports. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/2d7280f3 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/2d7280f3 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/2d7280f3 Branch: refs/heads/master Commit: 2d7280f33ac0a75a8259644e187f006a51e0fff7 Parents: f37b005 Author: Timothy Bish Authored: Tue Jun 2 17:17:36 2015 -0400 Committer: Timothy Bish Committed: Tue Jun 2 17:17:36 2015 -0400 ---------------------------------------------------------------------- .../stomp/StompInactivityMonitorTest.java | 145 +++++++++++++++++++ 1 file changed, 145 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/2d7280f3/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/StompInactivityMonitorTest.java ---------------------------------------------------------------------- diff --git a/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/StompInactivityMonitorTest.java b/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/StompInactivityMonitorTest.java new file mode 100644 index 0000000..20f4ed9 --- /dev/null +++ b/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/StompInactivityMonitorTest.java @@ -0,0 +1,145 @@ +/** + * 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.activemq.transport.stomp; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.Socket; +import java.util.Arrays; +import java.util.Collection; + +import javax.net.SocketFactory; +import javax.net.ssl.SSLSocketFactory; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test that the inactivity monitor works as expected. + */ +@RunWith(Parameterized.class) +public class StompInactivityMonitorTest extends StompTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(StompInactivityMonitorTest.class); + + private final String transportScheme; + + @Parameters(name="{0}") + public static Collection data() { + return Arrays.asList(new Object[][] { + { "stomp" }, + { "stomp+ssl" }, + { "stomp+nio" }, + { "stomp+nio+ssl" } + }); + } + + public StompInactivityMonitorTest(String transportScheme) { + this.transportScheme = transportScheme; + } + + @Test + public void test() throws Exception { + stompConnect(); + + String connectFrame = "STOMP\n" + + "login:system\n" + + "passcode:manager\n" + + "accept-version:1.1\n" + + "heart-beat:1000,0\n" + + "host:localhost\n" + + "\n" + Stomp.NULL; + + stompConnection.sendFrame(connectFrame); + String response = stompConnection.receiveFrame().trim(); + LOG.info("Broker sent response: {}", response); + + String messageHead = "SEND\n" + + "receipt:1" + "\n" + + "destination:/queue/" + getQueueName() + + "\n\n" + "AAAA"; + + stompConnection.sendFrame(messageHead); + + for (int i = 0; i < 30; i++) { + stompConnection.sendFrame("A"); + Thread.sleep(100); + } + + stompConnection.sendFrame(Stomp.NULL); + + response = stompConnection.receiveFrame().trim(); + assertTrue(response.startsWith("RECEIPT")); + } + + @Override + protected boolean isUseTcpConnector() { + return !transportScheme.contains("nio") && !transportScheme.contains("ssl"); + } + + @Override + protected boolean isUseSslConnector() { + return !transportScheme.contains("nio") && transportScheme.contains("ssl"); + } + + @Override + protected boolean isUseNioConnector() { + return transportScheme.contains("nio") && !transportScheme.contains("ssl"); + } + + @Override + protected boolean isUseNioPlusSslConnector() { + return transportScheme.contains("nio") && transportScheme.contains("ssl"); + } + + @Override + protected Socket createSocket() throws IOException { + int port = 0; + boolean useSSL = false; + + if (transportScheme.contains("ssl")) { + if (transportScheme.contains("nio")) { + port = this.nioSslPort; + } else { + port = this.sslPort; + } + + useSSL = true; + } else { + if (transportScheme.contains("nio")) { + port = this.nioPort; + } else { + port = this.port; + } + } + + SocketFactory factory = null; + + if (useSSL) { + factory = SSLSocketFactory.getDefault(); + } else { + factory = SocketFactory.getDefault(); + } + + return factory.createSocket("127.0.0.1", port); + } +}