distinguish a listening and a connecting StoreAndForward test

This commit is contained in:
Axel Uhl
2011-11-14 15:01:38 +01:00
parent da39f7f1d6
commit 8839f9d5d6
2 changed files with 15 additions and 7 deletions
@@ -213,7 +213,7 @@ public class StoreAndForward implements Runnable {
} else {
synchronized (this) {
receivingFromSailMaster = true;
logger.info("StoreAndForward issuing SailMaster connections to "+sailMasterHostname+":"+sailMasterPort);
logger.info("StoreAndForward issuing SailMaster connection to "+sailMasterHostname+":"+sailMasterPort);
notifyAll();
}
socket = new Socket(sailMasterHostname, sailMasterPort);
@@ -279,6 +279,11 @@ public class StoreAndForward implements Runnable {
} catch (Throwable e) {
if (!stopped) {
logger.throwing(StoreAndForward.class.getName(), "Error during forwarding message. Continuing...", e);
try {
Thread.sleep(1000l); // wait a little bit before trying to re-establish a connection
} catch (InterruptedException e1) {
logger.throwing(StoreAndForward.class.getName(), "Can't find any sleep...", e1);
}
}
}
}
@@ -30,8 +30,8 @@ import com.sap.sailing.domain.swisstimingadapter.persistence.impl.CollectionName
import com.sap.sailing.domain.swisstimingadapter.persistence.impl.FieldNames;
import com.sap.sailing.mongodb.Activator;
public class StoreAndForwardTest {
private static final Logger logger = Logger.getLogger(StoreAndForwardTest.class.getName());
public class ListeningStoreAndForwardTest {
private static final Logger logger = Logger.getLogger(ListeningStoreAndForwardTest.class.getName());
private static final int RECEIVE_PORT = 6543;
private static final int CLIENT_PORT = 6544;
@@ -47,8 +47,10 @@ public class StoreAndForwardTest {
@Before
public void setUp() throws UnknownHostException, IOException, InterruptedException {
logger.info("ListeningStoreAndForwardTest.setUp");
db = Activator.getDefaultInstance().getDB();
storeAndForward = new StoreAndForward(RECEIVE_PORT, CLIENT_PORT, SwissTimingFactory.INSTANCE, SwissTimingAdapterPersistence.INSTANCE);
swissTimingAdapterPersistence = SwissTimingAdapterPersistence.INSTANCE;
storeAndForward = new StoreAndForward(RECEIVE_PORT, CLIENT_PORT, SwissTimingFactory.INSTANCE, swissTimingAdapterPersistence);
sendingSocket = new Socket("localhost", RECEIVE_PORT);
sendingStream = sendingSocket.getOutputStream();
swissTimingFactory = SwissTimingFactory.INSTANCE;
@@ -59,18 +61,19 @@ public class StoreAndForwardTest {
/* upsert */ true, /* multi */ false);
DBCollection rawMessages = db.getCollection(CollectionNames.RAW_MESSAGES.name());
rawMessages.drop();
swissTimingAdapterPersistence = SwissTimingAdapterPersistence.INSTANCE;
}
@After
public void tearDown() throws InterruptedException, IOException {
logger.entering(getClass().getName(), "tearDown");
storeAndForward.stop();
connector.stop();
logger.exiting(getClass().getName(), "tearDown");
}
@Test
public void testSimpleRACMessage() throws IOException, InterruptedException {
logger.info("Starting ListeningStoreAndForwardTest.testSimpleRACMessage");
final List<Race> racesReceived = new ArrayList<Race>();
final boolean[] receivedSomething = new boolean[1];
connector.addSailMasterListener(new SailMasterAdapter() {
@@ -79,9 +82,9 @@ public class StoreAndForwardTest {
for (Race race : races) {
racesReceived.add(race);
}
synchronized (StoreAndForwardTest.this) {
synchronized (ListeningStoreAndForwardTest.this) {
receivedSomething[0] = true;
StoreAndForwardTest.this.notifyAll();
ListeningStoreAndForwardTest.this.notifyAll();
}
}
});