Search in sources :

Example 6 with DefaultEntityPropertiesForTesting

use of com.wavefront.agent.data.DefaultEntityPropertiesForTesting 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 }));
}
Also used : LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) DefaultEntityPropertiesForTesting(com.wavefront.agent.data.DefaultEntityPropertiesForTesting) UUID(java.util.UUID) Test(org.junit.Test)

Example 7 with DefaultEntityPropertiesForTesting

use of com.wavefront.agent.data.DefaultEntityPropertiesForTesting 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());
    }
}
Also used : ReceiveMessageRequest(com.amazonaws.services.sqs.model.ReceiveMessageRequest) Message(com.amazonaws.services.sqs.model.Message) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) ReportEvent(wavefront.report.ReportEvent) Event(com.wavefront.dto.Event) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) DefaultEntityPropertiesForTesting(com.wavefront.agent.data.DefaultEntityPropertiesForTesting) UUID(java.util.UUID) SendMessageRequest(com.amazonaws.services.sqs.model.SendMessageRequest) ReceiveMessageResult(com.amazonaws.services.sqs.model.ReceiveMessageResult) Test(org.junit.Test)

Example 8 with DefaultEntityPropertiesForTesting

use of com.wavefront.agent.data.DefaultEntityPropertiesForTesting 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());
}
Also used : HandlerKey(com.wavefront.agent.handlers.HandlerKey) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) DefaultEntityPropertiesFactoryForTesting(com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting) EntityPropertiesFactory(com.wavefront.agent.data.EntityPropertiesFactory) BufferedWriter(java.io.BufferedWriter) DefaultEntityPropertiesForTesting(com.wavefront.agent.data.DefaultEntityPropertiesForTesting) UUID(java.util.UUID) File(java.io.File) Test(org.junit.Test)

Aggregations

DefaultEntityPropertiesForTesting (com.wavefront.agent.data.DefaultEntityPropertiesForTesting)8 Test (org.junit.Test)8 UUID (java.util.UUID)7 LineDelimitedDataSubmissionTask (com.wavefront.agent.data.LineDelimitedDataSubmissionTask)6 File (java.io.File)5 EventDataSubmissionTask (com.wavefront.agent.data.EventDataSubmissionTask)4 Event (com.wavefront.dto.Event)4 ReportEvent (wavefront.report.ReportEvent)4 QueueFile (com.squareup.tape2.QueueFile)3 SourceTagSubmissionTask (com.wavefront.agent.data.SourceTagSubmissionTask)3 SourceTag (com.wavefront.dto.SourceTag)3 ReportSourceTag (wavefront.report.ReportSourceTag)3 DefaultEntityPropertiesFactoryForTesting (com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting)2 EntityPropertiesFactory (com.wavefront.agent.data.EntityPropertiesFactory)2 HandlerKey (com.wavefront.agent.handlers.HandlerKey)2 BufferedWriter (java.io.BufferedWriter)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Message (com.amazonaws.services.sqs.model.Message)1 ReceiveMessageRequest (com.amazonaws.services.sqs.model.ReceiveMessageRequest)1 ReceiveMessageResult (com.amazonaws.services.sqs.model.ReceiveMessageResult)1