Skip to content
This repository was archived by the owner on Jan 19, 2024. It is now read-only.

Commit d6765fb

Browse files
author
John Myers
committed
Support receiving SMILE-encoded events
1 parent 82ed686 commit d6765fb

3 files changed

Lines changed: 99 additions & 1 deletion

File tree

src/main/java/com/proofpoint/event/collector/EventResource.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ public Response write(List<Event> events)
6363
return processEvents(WRITER, events, WRITE);
6464
}
6565

66+
// Separate method to permit gathering of statistics
67+
@POST
68+
@Consumes("application/x-jackson-smile")
69+
public Response writeSmile(List<Event> events)
70+
throws IOException
71+
{
72+
return write(events);
73+
}
74+
6675
@POST
6776
@Path("/distribute")
6877
@Consumes(MediaType.APPLICATION_JSON)
@@ -72,6 +81,17 @@ public Response distribute(List<Event> events)
7281
return processEvents(DISTRIBUTOR, events, DISTRIBUTE);
7382
}
7483

84+
85+
// Separate method to permit gathering of statistics
86+
@POST
87+
@Path("/distribute")
88+
@Consumes("application/x-jackson-smile")
89+
public Response distributeSmile(List<Event> events)
90+
throws IOException
91+
{
92+
return distribute(events);
93+
}
94+
7595
private Response processEvents(EventProcessor processor, List<Event> events, ProcessType processType)
7696
throws IOException
7797
{

src/test/java/com/proofpoint/event/collector/TestEventResource.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ public void testWrite()
7979
verifyMetrics(WRITE, ImmutableList.of(new EventMetric("Test", VALID, 1)));
8080
}
8181

82+
@Test
83+
public void testWriteSmile()
84+
throws IOException
85+
{
86+
EventResource resource = new EventResource(ImmutableSet.<EventWriter>of(writer), new ServerConfig().setAcceptedEventTypes("Test"), eventCollectorStats);
87+
88+
Event event = new Event("Test", UUID.randomUUID().toString(), "test.local", new DateTime(), ARBITRARY_DATA);
89+
90+
List<Event> events = ImmutableList.of(event);
91+
Response response = resource.writeSmile(events);
92+
93+
verifyAcceptedResponse(response);
94+
95+
verifyWrittenAndDistributedEvents(events, ImmutableList.<Event>of());
96+
97+
verifyMetrics(WRITE, ImmutableList.of(new EventMetric("Test", VALID, 1)));
98+
}
99+
82100
@Test
83101
public void testWriteUnsupportedType()
84102
throws IOException
@@ -140,6 +158,24 @@ public void testDistribute()
140158
verifyMetrics(DISTRIBUTE, ImmutableList.of(new EventMetric("Test", VALID, 1)));
141159
}
142160

161+
@Test
162+
public void testDistributeSmile()
163+
throws IOException
164+
{
165+
EventResource resource = new EventResource(ImmutableSet.<EventWriter>of(writer), new ServerConfig().setAcceptedEventTypes("Test"), eventCollectorStats);
166+
167+
Event event = new Event("Test", UUID.randomUUID().toString(), "test.local", new DateTime(), ARBITRARY_DATA);
168+
169+
List<Event> events = ImmutableList.of(event);
170+
Response response = resource.distributeSmile(events);
171+
172+
verifyAcceptedResponse(response);
173+
174+
verifyWrittenAndDistributedEvents(ImmutableList.<Event>of(), events);
175+
176+
verifyMetrics(DISTRIBUTE, ImmutableList.of(new EventMetric("Test", VALID, 1)));
177+
}
178+
143179
@Test
144180
public void testDistributeUnsupportedType()
145181
throws IOException

src/test/java/com/proofpoint/event/collector/TestServer.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
*/
1616
package com.proofpoint.event.collector;
1717

18+
import com.fasterxml.jackson.databind.DeserializationFeature;
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
1821
import com.google.common.base.Charsets;
22+
import com.google.common.collect.ImmutableList;
1923
import com.google.common.collect.ImmutableMap;
2024
import com.google.common.io.Files;
2125
import com.google.common.io.Resources;
@@ -24,6 +28,7 @@
2428
import com.proofpoint.bootstrap.LifeCycleManager;
2529
import com.proofpoint.discovery.client.testing.TestingDiscoveryModule;
2630
import com.proofpoint.event.client.JsonEventModule;
31+
import com.proofpoint.http.client.BodyGenerator;
2732
import com.proofpoint.http.client.HttpClient;
2833
import com.proofpoint.http.client.StatusResponseHandler.StatusResponse;
2934
import com.proofpoint.http.client.StringResponseHandler.StringResponse;
@@ -43,6 +48,7 @@
4348

4449
import java.io.File;
4550
import java.io.IOException;
51+
import java.io.OutputStream;
4652
import java.net.URI;
4753
import java.util.concurrent.ExecutionException;
4854

@@ -60,7 +66,8 @@
6066

6167
public class TestServer
6268
{
63-
private JsonCodec<Object> OBJECT_CODEC = JsonCodec.jsonCodec(Object.class);
69+
private static final JsonCodec<Object> OBJECT_CODEC = JsonCodec.jsonCodec(Object.class);
70+
private static final ObjectMapper MAPPER = new ObjectMapper(new SmileFactory()).disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
6471
private HttpClient client;
6572
private TestingHttpServer server;
6673
private File tempStageDir;
@@ -145,6 +152,41 @@ public void testPostSingle()
145152
assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode());
146153
}
147154

155+
@Test
156+
public void testPostSmile()
157+
throws IOException, ExecutionException, InterruptedException
158+
{
159+
StatusResponse response = client.execute(preparePost()
160+
.setUri(urlFor("/v2/event"))
161+
.setHeader("Content-Type", "application/x-jackson-smile")
162+
.setBodyGenerator(new BodyGenerator()
163+
{
164+
@Override
165+
public void write(OutputStream outputStream)
166+
throws Exception
167+
{
168+
MAPPER.writeValue(outputStream, ImmutableList.of(
169+
ImmutableMap.of(
170+
"type", "Test",
171+
"uuid", "DCD36293-3072-4AFD-B6E3-A9EB9CE1F219",
172+
"host", "test.local",
173+
"timestamp", "2011-03-30T16:10:16.000Z",
174+
"data", ImmutableMap.of(
175+
"foo", "bar",
176+
"hello", "world"
177+
)
178+
)
179+
180+
)
181+
);
182+
}
183+
})
184+
.build(),
185+
createStatusResponseHandler());
186+
187+
assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode());
188+
}
189+
148190
@Test
149191
public void testPostMultiple()
150192
throws IOException, ExecutionException, InterruptedException

0 commit comments

Comments
 (0)