Merge pull request #56 from garyrussell/INTSAMPLES-76-4
* garyrussell-INTSAMPLES-76-4: INTSAMPLES-76 Wait for Server (Intermediate)
This commit is contained in:
@@ -23,11 +23,14 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||||
import org.springframework.core.task.TaskExecutor;
|
import org.springframework.core.task.TaskExecutor;
|
||||||
|
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
|
||||||
|
import org.springframework.integration.samples.tcpclientserver.support.ServerUtils;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
@@ -50,6 +53,14 @@ public class TcpClientServerDemoTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
SimpleGateway gw;
|
SimpleGateway gw;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
AbstractServerConnectionFactory crLfServer;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
ServerUtils.waitListening(this.crLfServer);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHappyDay() {
|
public void testHappyDay() {
|
||||||
String result = gw.send("999Hello world!"); // first 3 bytes is correlationid
|
String result = gw.send("999Hello world!"); // first 3 bytes is correlationid
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2002-2012 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed 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.springframework.integration.samples.tcpclientserver.support;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gary Russell
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ServerUtils {
|
||||||
|
|
||||||
|
public static void waitListening(AbstractServerConnectionFactory serverConnectionFactory) {
|
||||||
|
int n = 0;
|
||||||
|
while (!serverConnectionFactory.isListening()) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e1) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw new IllegalStateException(e1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n++ > 100) {
|
||||||
|
fail("Server didn't begin listening.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user