use of com.wavefront.agent.data.LineDelimitedDataSubmissionTask in project java by wavefrontHQ.
the class InstrumentedTaskQueueDelegateTest method testLineDelimitedTask.
@Test
public void testLineDelimitedTask() throws Exception {
AtomicLong time = new AtomicLong(77777);
for (RetryTaskConverter.CompressionType type : RetryTaskConverter.CompressionType.values()) {
System.out.println("LineDelimited task, compression type: " + type);
File file = new File(File.createTempFile("proxyTestConverter", null).getPath() + ".queue");
file.deleteOnExit();
TaskQueue<LineDelimitedDataSubmissionTask> queue = getTaskQueue(file, type);
queue.clear();
UUID proxyId = UUID.randomUUID();
LineDelimitedDataSubmissionTask task = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item1", "item2", "item3"), time::get);
task.enqueue(QueueingReason.RETRY);
queue.close();
TaskQueue<LineDelimitedDataSubmissionTask> readQueue = getTaskQueue(file, type);
LineDelimitedDataSubmissionTask readTask = readQueue.peek();
assertEquals(task.payload(), readTask.payload());
assertEquals(77777, readTask.getEnqueuedMillis());
}
}
use of com.wavefront.agent.data.LineDelimitedDataSubmissionTask in project java by wavefrontHQ.
the class RetryTaskConverterTest method testTaskSerialize.
@Test
public void testTaskSerialize() {
UUID proxyId = UUID.randomUUID();
LineDelimitedDataSubmissionTask task = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), null, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item1", "item2", "item3"), () -> 12345L);
RetryTaskConverter<LineDelimitedDataSubmissionTask> converter = new RetryTaskConverter<>("2878", RetryTaskConverter.CompressionType.NONE);
assertNull(converter.fromBytes(new byte[] { 0, 0, 0 }));
assertNull(converter.fromBytes(new byte[] { 'W', 'F', 0 }));
assertNull(converter.fromBytes(new byte[] { 'W', 'F', 1 }));
assertNull(converter.fromBytes(new byte[] { 'W', 'F', 1, 0 }));
}
use of com.wavefront.agent.data.LineDelimitedDataSubmissionTask in project java by wavefrontHQ.
the class SQSSubmissionQueueTest method scenarios.
@Parameterized.Parameters
public static Collection<Object[]> scenarios() {
Collection<Object[]> scenarios = new ArrayList<>();
for (TaskConverter.CompressionType type : TaskConverter.CompressionType.values()) {
RetryTaskConverter<LineDelimitedDataSubmissionTask> converter = new RetryTaskConverter<>("2878", type);
LineDelimitedDataSubmissionTask task = converter.fromBytes("WF\u0001\u0001{\"__CLASS\":\"com.wavefront.agent.data.LineDelimitedDataSubmissionTask\",\"enqueuedTimeMillis\":77777,\"attempts\":0,\"serverErrors\":0,\"handle\":\"2878\",\"entityType\":\"POINT\",\"format\":\"wavefront\",\"payload\":[\"java.util.ArrayList\",[\"item1\",\"item2\",\"item3\"]],\"enqueuedMillis\":77777}".getBytes());
scenarios.add(new Object[] { type, converter, task });
}
for (TaskConverter.CompressionType type : TaskConverter.CompressionType.values()) {
RetryTaskConverter<EventDataSubmissionTask> converter = new RetryTaskConverter<>("2878", type);
EventDataSubmissionTask task = converter.fromBytes("WF\u0001\u0001{\"__CLASS\":\"com.wavefront.agent.data.EventDataSubmissionTask\",\"enqueuedTimeMillis\":77777,\"attempts\":0,\"serverErrors\":0,\"handle\":\"2878\",\"entityType\":\"EVENT\",\"events\":[\"java.util.ArrayList\",[{\"name\":\"Event name for testing\",\"startTime\":77777000,\"endTime\":77777001,\"annotations\":[\"java.util.HashMap\",{\"severity\":\"INFO\"}],\"dimensions\":[\"java.util.HashMap\",{\"multi\":[\"java.util.ArrayList\",[\"bar\",\"baz\"]]}],\"hosts\":[\"java.util.ArrayList\",[\"host1\",\"host2\"]],\"tags\":[\"java.util.ArrayList\",[\"tag1\"]]}]],\"enqueuedMillis\":77777}".getBytes());
scenarios.add(new Object[] { type, converter, task });
}
return scenarios;
}
use of com.wavefront.agent.data.LineDelimitedDataSubmissionTask in project java by wavefrontHQ.
the class SQSSubmissionQueueTest method testTaskRead.
@Test
public void testTaskRead() throws IOException {
SQSSubmissionQueue queue = getTaskQueue();
UUID proxyId = UUID.randomUUID();
DataSubmissionTask<? extends DataSubmissionTask<?>> task;
if (this.expectedTask instanceof LineDelimitedDataSubmissionTask) {
task = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item1", "item2", "item3"), time::get);
} else if (this.expectedTask instanceof EventDataSubmissionTask) {
task = new EventDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "2878", ImmutableList.of(new Event(ReportEvent.newBuilder().setStartTime(time.get() * 1000).setEndTime(time.get() * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).setAnnotations(ImmutableMap.of("severity", "INFO")).setTags(ImmutableList.of("tag1")).build())), time::get);
} else {
task = null;
}
expect(client.sendMessage(new SendMessageRequest(queueUrl, queue.encodeMessageForDelivery(this.expectedTask)))).andReturn(null);
replay(client);
task.enqueue(QueueingReason.RETRY);
reset(client);
ReceiveMessageRequest msgRequest = new ReceiveMessageRequest().withMaxNumberOfMessages(1).withWaitTimeSeconds(1).withQueueUrl(queueUrl);
ReceiveMessageResult msgResult = new ReceiveMessageResult().withMessages(new Message().withBody(queue.encodeMessageForDelivery(task)).withReceiptHandle("handle1"));
expect(client.receiveMessage(msgRequest)).andReturn(msgResult);
replay(client);
if (this.expectedTask instanceof LineDelimitedDataSubmissionTask) {
LineDelimitedDataSubmissionTask readTask = (LineDelimitedDataSubmissionTask) queue.peek();
assertEquals(((LineDelimitedDataSubmissionTask) task).payload(), readTask.payload());
assertEquals(((LineDelimitedDataSubmissionTask) this.expectedTask).payload(), readTask.payload());
assertEquals(77777, readTask.getEnqueuedMillis());
}
if (this.expectedTask instanceof EventDataSubmissionTask) {
EventDataSubmissionTask readTask = (EventDataSubmissionTask) queue.peek();
assertEquals(((EventDataSubmissionTask) task).payload(), readTask.payload());
assertEquals(((EventDataSubmissionTask) this.expectedTask).payload(), readTask.payload());
assertEquals(77777, readTask.getEnqueuedMillis());
}
}
use of com.wavefront.agent.data.LineDelimitedDataSubmissionTask in project java by wavefrontHQ.
the class QueueExporterTest method testQueueExporterWithRetainData.
@Test
public void testQueueExporterWithRetainData() throws Exception {
File file = new File(File.createTempFile("proxyTestConverter", null).getPath() + ".queue");
file.deleteOnExit();
String bufferFile = file.getAbsolutePath();
TaskQueueFactory taskQueueFactory = new TaskQueueFactoryImpl(bufferFile, false, false, 128);
EntityPropertiesFactory entityPropFactory = new DefaultEntityPropertiesFactoryForTesting();
QueueExporter qe = new QueueExporter(bufferFile, "2878", bufferFile + "-output", true, taskQueueFactory, entityPropFactory);
BufferedWriter mockedWriter = EasyMock.createMock(BufferedWriter.class);
reset(mockedWriter);
HandlerKey key = HandlerKey.of(ReportableEntityType.POINT, "2878");
TaskQueue<LineDelimitedDataSubmissionTask> queue = taskQueueFactory.getTaskQueue(key, 0);
queue.clear();
UUID proxyId = UUID.randomUUID();
LineDelimitedDataSubmissionTask task = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item1", "item2", "item3"), () -> 12345L);
task.enqueue(QueueingReason.RETRY);
LineDelimitedDataSubmissionTask task2 = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item4", "item5"), () -> 12345L);
task2.enqueue(QueueingReason.RETRY);
qe.export();
File outputTextFile = new File(file.getAbsolutePath() + "-output.points.2878.0.txt");
assertEquals(ImmutableList.of("item1", "item2", "item3", "item4", "item5"), Files.asCharSource(outputTextFile, Charsets.UTF_8).readLines());
assertEquals(2, taskQueueFactory.getTaskQueue(key, 0).size());
}
Aggregations