From 91d626b2e55d767f424cd910fa2c371eb31043f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Blu=CC=88mke?= <lbl@informatik.uni-kiel.de> Date: Wed, 18 May 2016 09:41:28 +0200 Subject: [PATCH] registry records can be detected --- .../plugin/reader/amqp/AMQPReaderTest.java | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) 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 c4bfe7d8..e80b15aa 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) { -- GitLab