Skip to content
Snippets Groups Projects
Commit 91d626b2 authored by Lars Erik Blümke's avatar Lars Erik Blümke
Browse files

registry records can be detected

parent fe022edc
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment