From 8cde7e24f2fd1f6cc22ef992984f91527cd58df5 Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 18 Aug 2012 11:59:31 +0200 Subject: [PATCH] Re-enabled commented tests --- .../server/ServerIntegrationTest.java | 316 +++++++++--------- 1 file changed, 158 insertions(+), 158 deletions(-) diff --git a/parser/src/test/java/org/dna/mqtt/moquette/server/ServerIntegrationTest.java b/parser/src/test/java/org/dna/mqtt/moquette/server/ServerIntegrationTest.java index ed0cfb39..23d73865 100644 --- a/parser/src/test/java/org/dna/mqtt/moquette/server/ServerIntegrationTest.java +++ b/parser/src/test/java/org/dna/mqtt/moquette/server/ServerIntegrationTest.java @@ -37,164 +37,164 @@ public class ServerIntegrationTest { } } -// -// @Test -// public void testSubscribe() throws IOException, InterruptedException { -//// startServer(); -// Client client = new Client("localhost", Server.PORT); -//// Client client = new Client("test.mosquitto.org", 1883); -// client.connect(); -// -// -// client.subscribe("/topic", new IPublishCallback() { -// -// public void published(String topic, byte[] message) { -// received = true; -// } -// }); -// -// client.publish("/topic", "Test my payload".getBytes()); -// -// client.close(); -// client.shutdown(); -// -// assertTrue(received); -// } -// -// -// @Test -// public void testCleanSession_maintainClientSubscriptions() { -// Client client = new Client("localhost", Server.PORT/*, "CLID_123"*/); -// client.connect(false); //without session cleanup -// -// client.subscribe("/topic", new IPublishCallback() { -// -// public void published(String topic, byte[] message) { -// received = true; -// } -// }); -// client.close(); -// -// //Exercise that the client maintain the subscriptions -// client.connect(false); -// client.publish("/topic", "Test my payload".getBytes()); -// client.close(); -// -// //Verify -// assertTrue(received); -// -// //TearDown -// client.shutdown(); -// } -// -// @Test -// public void testCleanSession_maintainClientSubscriptions_againstClientDestruction() { -// Client client = new Client("localhost", Server.PORT, "CLID_123"); -// client.connect(false); //without session cleanup -// -// client.subscribe("/topic", new IPublishCallback() { -// -// public void published(String topic, byte[] message) { -// received = true; -// } -// }); -// client.close(); -// client.shutdown(); -// -// //Exercise that the client maintain the subscriptions -// client = new Client("localhost", Server.PORT, "CLID_123"); -// client.register("/topic", new IPublishCallback() { -// -// public void published(String topic, byte[] message) { -// received = true; -// } -// }); -// client.connect(false); -// client.publish("/topic", "Test my payload".getBytes()); -// client.close(); -// -// //Verify -// assertTrue(received); -// -// //TearDown -// client.shutdown(); -// } -// -// -// /** -// * Check that after a client has connected with clean session false, subscribed -// * to some topic and exited, if it reconnect with clean session true, the server -// * correctly cleanup every previous subscription -// */ -// @Test -// public void testCleanSession_correctlyClientSubscriptions() { -// Client client = new Client("localhost", Server.PORT, "CLID_123"); -// client.connect(false); //without session cleanup -// -// client.subscribe("/topic", new IPublishCallback() { -// -// public void published(String topic, byte[] message) { -// received = true; -// } -// }); -// client.close(); -// client.shutdown(); -// -// //Exercise that the client maintain the subscriptions -// client = new Client("localhost", Server.PORT, "CLID_123"); -// client.register("/topic", new IPublishCallback() { -// -// public void published(String topic, byte[] message) { -// received = true; -// } -// }); -// client.connect(true); -// client.publish("/topic", "Test my payload".getBytes()); -// client.close(); -// -// //Verify -// assertFalse(received); -// -// //TearDown -// client.shutdown(); -// } -// -// -// @Test -// public void testCleanSession_maintainClientSubscriptions_withServerRestart() throws IOException { -// Client client = new Client("localhost", Server.PORT, "CLID_123"); -// client.connect(false); //without session cleanup -// -// client.subscribe("/topic", new IPublishCallback() { -// -// public void published(String topic, byte[] message) { -// received = true; -// } -// }); -// client.close(); -// client.shutdown(); -// server.stopServer(); -// -// server.startServer(); -// -// //Exercise that the client maintain the subscriptions -// client = new Client("localhost", Server.PORT, "CLID_123"); -// client.register("/topic", new IPublishCallback() { -// -// public void published(String topic, byte[] message) { -// received = true; -// } -// }); -// client.connect(false); -// client.publish("/topic", "Test my payload".getBytes()); -// client.close(); -// -// //Verify -// assertTrue(received); -// -// //TearDown -// client.shutdown(); -// } + + @Test + public void testSubscribe() throws IOException, InterruptedException { +// startServer(); + Client client = new Client("localhost", Server.PORT); +// Client client = new Client("test.mosquitto.org", 1883); + client.connect(); + + + client.subscribe("/topic", new IPublishCallback() { + + public void published(String topic, byte[] message) { + received = true; + } + }); + + client.publish("/topic", "Test my payload".getBytes()); + + client.close(); + client.shutdown(); + + assertTrue(received); + } + + + @Test + public void testCleanSession_maintainClientSubscriptions() { + Client client = new Client("localhost", Server.PORT/*, "CLID_123"*/); + client.connect(false); //without session cleanup + + client.subscribe("/topic", new IPublishCallback() { + + public void published(String topic, byte[] message) { + received = true; + } + }); + client.close(); + + //Exercise that the client maintain the subscriptions + client.connect(false); + client.publish("/topic", "Test my payload".getBytes()); + client.close(); + + //Verify + assertTrue(received); + + //TearDown + client.shutdown(); + } + + @Test + public void testCleanSession_maintainClientSubscriptions_againstClientDestruction() { + Client client = new Client("localhost", Server.PORT, "CLID_123"); + client.connect(false); //without session cleanup + + client.subscribe("/topic", new IPublishCallback() { + + public void published(String topic, byte[] message) { + received = true; + } + }); + client.close(); + client.shutdown(); + + //Exercise that the client maintain the subscriptions + client = new Client("localhost", Server.PORT, "CLID_123"); + client.register("/topic", new IPublishCallback() { + + public void published(String topic, byte[] message) { + received = true; + } + }); + client.connect(false); + client.publish("/topic", "Test my payload".getBytes()); + client.close(); + + //Verify + assertTrue(received); + + //TearDown + client.shutdown(); + } + + + /** + * Check that after a client has connected with clean session false, subscribed + * to some topic and exited, if it reconnect with clean session true, the server + * correctly cleanup every previous subscription + */ + @Test + public void testCleanSession_correctlyClientSubscriptions() { + Client client = new Client("localhost", Server.PORT, "CLID_123"); + client.connect(false); //without session cleanup + + client.subscribe("/topic", new IPublishCallback() { + + public void published(String topic, byte[] message) { + received = true; + } + }); + client.close(); + client.shutdown(); + + //Exercise that the client maintain the subscriptions + client = new Client("localhost", Server.PORT, "CLID_123"); + client.register("/topic", new IPublishCallback() { + + public void published(String topic, byte[] message) { + received = true; + } + }); + client.connect(true); + client.publish("/topic", "Test my payload".getBytes()); + client.close(); + + //Verify + assertFalse(received); + + //TearDown + client.shutdown(); + } + + + @Test + public void testCleanSession_maintainClientSubscriptions_withServerRestart() throws IOException { + Client client = new Client("localhost", Server.PORT, "CLID_123"); + client.connect(false); //without session cleanup + + client.subscribe("/topic", new IPublishCallback() { + + public void published(String topic, byte[] message) { + received = true; + } + }); + client.close(); + client.shutdown(); + server.stopServer(); + + server.startServer(); + + //Exercise that the client maintain the subscriptions + client = new Client("localhost", Server.PORT, "CLID_123"); + client.register("/topic", new IPublishCallback() { + + public void published(String topic, byte[] message) { + received = true; + } + }); + client.connect(false); + client.publish("/topic", "Test my payload".getBytes()); + client.close(); + + //Verify + assertTrue(received); + + //TearDown + client.shutdown(); + } @Test