diff --git a/src/main/java/telraam/beacon/Beacon.java b/src/main/java/telraam/beacon/Beacon.java index d48e05e..0b0efcd 100644 --- a/src/main/java/telraam/beacon/Beacon.java +++ b/src/main/java/telraam/beacon/Beacon.java @@ -56,7 +56,6 @@ public void run() { int c = is.read(buf); if (c < 0) throw new EOFException(); - System.out.println("" + (int) buf[0]); for (int i = 0; i < c; i++) { byte b = buf[i]; diff --git a/src/test/java/telraam/beacon/BeaconTest.java b/src/test/java/telraam/beacon/BeaconTest.java index 18dfcc7..6a9ab2a 100644 --- a/src/test/java/telraam/beacon/BeaconTest.java +++ b/src/test/java/telraam/beacon/BeaconTest.java @@ -20,12 +20,12 @@ import java.util.logging.Level; /** -* Beacon integration test. -* Spoofing ServerSocket and Socket so you can write to it at will. -* TODO: Test socket exception, but I don't really know what could fail. -* -* @author Arthur Vercruysse -*/ + * Beacon integration test. Spoofing ServerSocket and Socket so you can write to + * it at will. TODO: Test socket exception, but I don't really know what could + * fail. + * + * @author Arthur Vercruysse + */ public class BeaconTest { private static Logger logger = Logger.getLogger(BeaconTest.class.getName()); @@ -133,6 +133,7 @@ public void testEverythingBeacon() throws Exception { ba.onError((e) -> { logger.log(Level.SEVERE, "error", e); errors.incrementAndGet(); + barrier.release(); return null; }); @@ -157,8 +158,8 @@ public void testEverythingBeacon() throws Exception { // Check if no beacon messages are sent with incomplete data // Aka do they buffer correctly? - for (OurSocket s: connectedSockets) { - s.write("hadeksfd".getBytes(), false); + for (OurSocket s : connectedSockets) { + s.write("<<<>>>".getBytes(), true); } barrier.acquire(8); @@ -178,8 +179,31 @@ public void testEverythingBeacon() throws Exception { assertEquals(data.get(), connectedSockets.size()); assertEquals(errors.get(), 0); + // Test invalid msg send + + // Invalid message + connectedSockets.get(0).write("<<<>>>".getBytes(), true); + + barrier.acquire(8); + barrier.release(8); + assertEquals(errors.get(), 1); + + // No opening tag + connectedSockets.get(0).write("<<>>>".getBytes(), true); + + barrier.acquire(8); + barrier.release(8); + assertEquals(errors.get(), 2); + + // 2 Opening tags + connectedSockets.get(0).write("<<<