diff --git a/src/test/java/kieker/analysis/plugin/reader/amqp/AMQPReaderTest.java b/src/test/java/kieker/analysis/plugin/reader/amqp/AMQPReaderTest.java index c4bfe7d8a5f67cdff4f1b7ffa7df21a73790f9a3..e80b15aa772f055cf6205001ddf901d9d1b02fa8 100644 --- a/src/test/java/kieker/analysis/plugin/reader/amqp/AMQPReaderTest.java +++ b/src/test/java/kieker/analysis/plugin/reader/amqp/AMQPReaderTest.java @@ -5,14 +5,11 @@ import static teetime.framework.test.StageTester.test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; -import java.net.URISyntaxException; import java.nio.ByteBuffer; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; import java.util.LinkedList; import java.util.List; -import java.util.concurrent.TimeoutException; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -40,6 +37,7 @@ public class AMQPReaderTest { private final String queueName = "testQueue"; private final int heartbeat = 60; private final Log log = LogFactory.getLog(this.getClass().getName()); + ILookup<String> stringRegistry = new Lookup<String>(); // AMQP connection parts private Connection connection; @@ -61,40 +59,50 @@ public class AMQPReaderTest { public void initializeAMQPReader() { amqpReader = new AMQPReader(uri, queueName, heartbeat, log); record = new CPUUtilizationRecord(timestamp, hostname, cpuID, user, system, wait, nice, irq, totalUtilisation, idle); - registryRecord = new RegistryRecord(0xFFFFFFFF, "holla"); - } + registryRecord = new RegistryRecord(-1, "holla"); - @Test - public void simpleAMQPTest() { new ReaderThread().start(); try { - connection = createConnection(); + final ConnectionFactory connectionFactory = new ConnectionFactory(); + + connectionFactory.setUri(this.uri); + connectionFactory.setRequestedHeartbeat(this.heartbeat); + + connection = connectionFactory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(queueName, false, false, false, null); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void simpleAMQPTest() { + + // Sending the test record as a byte array + ByteBuffer buffer = ByteBuffer.allocate(1000); + registryRecord.writeBytes(buffer, stringRegistry); - ILookup<String> stringRegistry = new Lookup<String>(); - // Sending the test record as a byte array - ByteBuffer buffer = ByteBuffer.allocate(1000); - registryRecord.writeBytes(buffer, stringRegistry); - System.out.println("RecordType before sending " + buffer.get() + buffer.get() + buffer.get()); - // channel.basicPublish("", queueName, null, buffer); + try { + System.out.println("RecordType before sending " + buffer.array()[0]); + channel.basicPublish("", queueName, null, buffer.array()); System.out.println("Sent record"); - channel.close(); - connection.close(); } catch (Exception e) { e.printStackTrace(); } - } - - private Connection createConnection() throws IOException, TimeoutException, KeyManagementException, NoSuchAlgorithmException, URISyntaxException { - final ConnectionFactory connectionFactory = new ConnectionFactory(); - connectionFactory.setUri(this.uri); - connectionFactory.setRequestedHeartbeat(this.heartbeat); + } - return connectionFactory.newConnection(); + @After + public void closeConnection() { + try { + channel.close(); + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } } private byte[] serialize(final Object object) {