Skip to content

Commit f085b26

Browse files
author
Ludovic Boutros
committed
Fix: date extraction test should use locale
1 parent 4e58b43 commit f085b26

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/test/java/com/splunk/kafka/connect/SplunkSinkTaskTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.junit.Test;
3131

3232
import java.text.ParseException;
33+
import java.text.SimpleDateFormat;
34+
import java.time.Instant;
3335
import java.util.*;
3436

3537
public class SplunkSinkTaskTest {
@@ -249,14 +251,27 @@ public void putWithRawAndAck() {
249251

250252
@Test
251253
public void checkExtractedTimestamp() {
254+
255+
252256
SplunkSinkTask task = new SplunkSinkTask();
253-
Collection<SinkRecord> record = createSinkRecords(1,"{\"id\": \"19\",\"host\":\"host-01\",\"source\":\"bu\",\"fields\":{\"hn\":\"hostname1\",\"CLASS\":\"class1\",\"cust_id\":\"000013934\",\"time\": \"Jun 13 2010 23:11:52.454 UTC\",\"category\":\"IFdata\",\"ifname\":\"LoopBack7\",\"IFdata.Bits received\":\"0\",\"IFdata.Bits sent\":\"0\"}");
254257
UnitUtil uu = new UnitUtil(0);
255258
Map<String, String> config = uu.createTaskConfig();
256259
config.put(SplunkSinkConnectorConfig.RAW_CONF, String.valueOf(false));
257260
config.put(SplunkSinkConnectorConfig.ENABLE_TIMESTAMP_EXTRACTION_CONF, String.valueOf(true));
258261
config.put(SplunkSinkConnectorConfig.REGEX_CONF, "\\\"time\\\":\\s*\\\"(?<time>.*?)\"");
259262
config.put(SplunkSinkConnectorConfig.TIMESTAMP_FORMAT_CONF, "MMM dd yyyy HH:mm:ss.SSS zzz");
263+
config.put(SplunkSinkConnectorConfig.TIMESTAMP_TIMEZONE_CONF, "UTC");
264+
265+
SimpleDateFormat df = new SimpleDateFormat(config.get(SplunkSinkConnectorConfig.TIMESTAMP_FORMAT_CONF));
266+
df.setTimeZone(TimeZone.getTimeZone("UTC"));
267+
268+
double instantDouble = 1.276470712454E12;
269+
String formattedDate = df.format(Date.from(Instant.ofEpochMilli(Double.valueOf(instantDouble).longValue())));
270+
271+
Collection<SinkRecord> record = createSinkRecords(1,"{\"id\": \"19\",\"host\":\"host-01\",\"source\":\"bu\",\"fields\":{\"hn\":\"hostname1\",\"CLASS\":\"class1\",\"cust_id\":\"000013934\",\"time\": \"" +
272+
formattedDate +
273+
"\",\"category\":\"IFdata\",\"ifname\":\"LoopBack7\",\"IFdata.Bits received\":\"0\",\"IFdata.Bits sent\":\"0\"}");
274+
260275
HecMock hec = new HecMock(task);
261276
hec.setSendReturnResult(HecMock.success);
262277
task.setHec(hec);
@@ -269,7 +284,7 @@ public void checkExtractedTimestamp() {
269284
List<Event> event_list = batch.getEvents();
270285
Iterator<Event> iterator = event_list.listIterator() ;
271286
Event event = iterator.next();
272-
Assert.assertEquals(1.276470712454E9, event.getTime(), 0);
287+
Assert.assertEquals(instantDouble / 1000, event.getTime(), 0);
273288
break;
274289
}
275290
task.stop();

0 commit comments

Comments
 (0)