flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject git commit: FLUME-1712: Regex Extractor Interceptor tests have timezone issues
Date Thu, 15 Nov 2012 17:28:19 GMT
Updated Branches:
  refs/heads/flume-1.3.0 77c366894 -> f432c571e


FLUME-1712: Regex Extractor Interceptor tests have timezone issues

(Brock Noland via Brock Noland)


Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/f432c571
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/f432c571
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/f432c571

Branch: refs/heads/flume-1.3.0
Commit: f432c571ebca03f3c1fc2050d7b2be6d75351da2
Parents: 77c3668
Author: Brock Noland <brock@apache.org>
Authored: Thu Nov 15 11:27:31 2012 -0600
Committer: Brock Noland <brock@apache.org>
Committed: Thu Nov 15 11:27:47 2012 -0600

----------------------------------------------------------------------
 .../interceptor/TestRegexExtractorInterceptor.java |   12 +++++++++---
 ...tRegexExtractorInterceptorMillisSerializer.java |   11 ++++++++---
 2 files changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/f432c571/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptor.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptor.java
b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptor.java
index 61749c3..f75d315 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptor.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptor.java
@@ -21,6 +21,8 @@ import org.apache.flume.Context;
 import org.apache.flume.Event;
 import org.apache.flume.event.EventBuilder;
 import org.apache.flume.interceptor.Interceptor.Builder;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -159,7 +161,11 @@ public class TestRegexExtractorInterceptor {
   @Test
   public void shouldExtractAddHeadersUsingSpecifiedSerializer()
       throws Exception {
-    String body = "2012-10-17 14:34:44,338";
+    long now = (System.currentTimeMillis() / 60000L) * 60000L;
+    String pattern = "yyyy-MM-dd HH:mm:ss,SSS";
+    DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);
+    String body = formatter.print(now);
+    System.out.println(body);
     Context context = new Context();
     // Skip the second group
     context.put(RegexExtractorInterceptor.REGEX,
@@ -179,8 +185,8 @@ public class TestRegexExtractorInterceptor {
 
     Event event = EventBuilder.withBody(body, Charsets.UTF_8);
     Event expected = EventBuilder.withBody(body, Charsets.UTF_8);
-    expected.getHeaders().put("timestamp", "1350509640000");
-    expected.getHeaders().put("data", ":44,338");
+    expected.getHeaders().put("timestamp", String.valueOf(now));
+    expected.getHeaders().put("data", ":00,000");
 
     Event actual = fixture.intercept(event);
 

http://git-wip-us.apache.org/repos/asf/flume/blob/f432c571/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorMillisSerializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorMillisSerializer.java
b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorMillisSerializer.java
index 1f87d9a..ac46131 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorMillisSerializer.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorMillisSerializer.java
@@ -20,6 +20,8 @@ package org.apache.flume.interceptor;
 import junit.framework.Assert;
 
 import org.apache.flume.Context;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
 import org.junit.Test;
 
 public class TestRegexExtractorInterceptorMillisSerializer {
@@ -52,10 +54,13 @@ public class TestRegexExtractorInterceptorMillisSerializer {
   public void shouldReturnMillisFromPattern() {
     RegexExtractorInterceptorMillisSerializer fixture = new RegexExtractorInterceptorMillisSerializer();
     Context context = new Context();
-    context.put("pattern", "yyyy-MM-dd HH:mm:ss");
+    String pattern = "yyyy-MM-dd HH:mm:ss";
+    context.put("pattern", pattern);
     fixture.configure(context);
 
-    Assert.assertEquals("1269616953000",
-        fixture.serialize("2010-03-26 08:22:33"));
+    DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);
+    long time = (System.currentTimeMillis() / 1000L) * 1000L;
+    Assert.assertEquals(String.valueOf(time),
+        fixture.serialize(formatter.print(time)));
   }
 }


Mime
View raw message