Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix http event client support for V1 events coming from the http server
- Loading branch information
Showing
6 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
event/src/test/java/com/proofpoint/event/client/TestJsonEventWriterV1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.proofpoint.event.client; | ||
|
||
import com.google.common.base.Charsets; | ||
import com.google.common.collect.ImmutableList; | ||
import org.joda.time.DateTime; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
import static com.proofpoint.event.client.EventTypeMetadata.getValidEventTypeMetaDataSet; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
public class TestJsonEventWriterV1 | ||
{ | ||
private JsonEventWriter eventWriter; | ||
|
||
@BeforeMethod | ||
public void setup() | ||
throws Exception | ||
{ | ||
Set<EventTypeMetadata<?>> eventTypes = getValidEventTypeMetaDataSet(FixedDummyEventClass.class); | ||
eventWriter = new JsonEventWriter(eventTypes, new HttpEventClientConfig().setJsonVersion(1)); | ||
} | ||
|
||
@Test | ||
public void testEventWriter() | ||
throws Exception | ||
{ | ||
assertEventJson(createEventGenerator(TestingUtils.getEvents()), "V1events.json"); | ||
} | ||
|
||
@Test | ||
public void testNullValue() | ||
throws Exception | ||
{ | ||
FixedDummyEventClass event = new FixedDummyEventClass( | ||
"localhost", new DateTime("2011-09-09T01:59:59.999Z"), UUID.fromString("1ea8ca34-db36-11e0-b76f-8b7d505ab1ad"), 123, null); | ||
|
||
assertEventJson(createEventGenerator(ImmutableList.of(event)), "V1event.json"); | ||
} | ||
|
||
private void assertEventJson(EventClient.EventGenerator<?> events, String resource) | ||
throws Exception | ||
{ | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
|
||
eventWriter.writeEvents(events, out); | ||
|
||
String json = out.toString(Charsets.UTF_8.name()); | ||
assertEquals(json, TestingUtils.getNormalizedJson(resource)); | ||
} | ||
|
||
private static <T> EventClient.EventGenerator<T> createEventGenerator(final Iterable<T> events) | ||
{ | ||
return new EventClient.EventGenerator<T>() | ||
{ | ||
@Override | ||
public void generate(EventClient.EventPoster<T> eventPoster) | ||
throws IOException | ||
{ | ||
for (T event : events) { | ||
eventPoster.post(event); | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"name":"FixedDummy", | ||
"type":"metrics", | ||
"host":"localhost", | ||
"timestamp":1315533599999, | ||
"data":[ | ||
{ | ||
"name":"IntValue", | ||
"value":123 | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"name":"FixedDummy", | ||
"type":"metrics", | ||
"host":"localhost", | ||
"timestamp":1315532128333, | ||
"data":[ | ||
{ | ||
"name":"IntValue", | ||
"value":5678 | ||
}, | ||
{ | ||
"name":"StringValue", | ||
"value":"foo" | ||
} | ||
] | ||
}, | ||
{ | ||
"name":"FixedDummy", | ||
"type":"metrics", | ||
"host":"localhost", | ||
"timestamp":1315532598123, | ||
"data":[ | ||
{ | ||
"name":"IntValue", | ||
"value":1 | ||
}, | ||
{ | ||
"name":"StringValue", | ||
"value":"bar" | ||
} | ||
] | ||
}, | ||
{ | ||
"name":"FixedDummy", | ||
"type":"metrics", | ||
"host":"localhost", | ||
"timestamp":1315532755555, | ||
"data":[ | ||
{ | ||
"name":"IntValue", | ||
"value":1234 | ||
}, | ||
{ | ||
"name":"StringValue", | ||
"value":"hello" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters