This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/master by this push:
     new 1a24059  [KARAF-5475] Fix tests to be timezone independent
1a24059 is described below

commit 1a240598c6cb593ab32ef91ede9aca6eb6ea96f4
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Nov 20 08:04:01 2017 +0100

    [KARAF-5475] Fix tests to be timezone independent
---
 audit/src/main/java/org/apache/karaf/audit/Activator.java         | 8 ++++++--
 .../main/java/org/apache/karaf/audit/layout/Rfc3164Layout.java    | 8 +++++---
 .../main/java/org/apache/karaf/audit/layout/Rfc5424Layout.java    | 8 +++++---
 audit/src/test/java/org/apache/karaf/audit/TestPerf.java          | 4 +++-
 .../test/java/org/apache/karaf/audit/logger/EventLoggerTest.java  | 6 ++++--
 5 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/audit/src/main/java/org/apache/karaf/audit/Activator.java 
b/audit/src/main/java/org/apache/karaf/audit/Activator.java
index 1066aed..bc1ddf5 100644
--- a/audit/src/main/java/org/apache/karaf/audit/Activator.java
+++ b/audit/src/main/java/org/apache/karaf/audit/Activator.java
@@ -51,6 +51,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Set;
+import java.util.TimeZone;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.TimeUnit;
@@ -186,11 +187,14 @@ public class Activator extends BaseActivator implements 
ManagedService {
             case "rfc3164":
                 return new Rfc3164Layout(getInt(prefix + ".facility", 16),
                         getInt(prefix + ".priority", 5),
-                        getInt(prefix + ".enterprise", 
Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER));
+                        getInt(prefix + ".enterprise", 
Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER),
+                        TimeZone.getDefault(),
+                        Locale.ENGLISH);
             case "rfc5424":
                 return new Rfc5424Layout(getInt(prefix + ".facility", 16),
                                          getInt(prefix + ".priority", 5),
-                                         getInt(prefix + ".enterprise", 
Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER));
+                                         getInt(prefix + ".enterprise", 
Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER),
+                                         TimeZone.getDefault());
             case "gelf":
                 return new GelfLayout();
             default:
diff --git 
a/audit/src/main/java/org/apache/karaf/audit/layout/Rfc3164Layout.java 
b/audit/src/main/java/org/apache/karaf/audit/layout/Rfc3164Layout.java
index 0f77985..0e3e984 100644
--- a/audit/src/main/java/org/apache/karaf/audit/layout/Rfc3164Layout.java
+++ b/audit/src/main/java/org/apache/karaf/audit/layout/Rfc3164Layout.java
@@ -21,6 +21,8 @@ import org.apache.karaf.audit.util.Buffer;
 import org.apache.karaf.audit.util.FastDateFormat;
 
 import java.io.IOException;
+import java.util.Locale;
+import java.util.TimeZone;
 
 public class Rfc3164Layout extends AbstractLayout {
 
@@ -29,18 +31,18 @@ public class Rfc3164Layout extends AbstractLayout {
     protected final int facility;
     protected final int priority;
     protected final int enterpriseNumber;
+    protected final FastDateFormat fastDateFormat;
 
     protected String hdr1;
     protected String hdr2;
     protected String hdr3;
 
-    protected FastDateFormat fastDateFormat = new FastDateFormat();
-
-    public Rfc3164Layout(int facility, int priority, int enterpriseNumber) {
+    public Rfc3164Layout(int facility, int priority, int enterpriseNumber, 
TimeZone timeZone, Locale locale) {
         super(new Buffer(Buffer.Format.Syslog));
         this.facility = facility;
         this.priority = priority;
         this.enterpriseNumber = enterpriseNumber;
+        this.fastDateFormat = new FastDateFormat(timeZone, locale);
 
         hdr1 = "<" + ((facility << 3) + priority) + ">";
         hdr2 = " " + hostName + " " + appName + " " + procId + " ";
diff --git 
a/audit/src/main/java/org/apache/karaf/audit/layout/Rfc5424Layout.java 
b/audit/src/main/java/org/apache/karaf/audit/layout/Rfc5424Layout.java
index 5bd314b..3980cb1 100644
--- a/audit/src/main/java/org/apache/karaf/audit/layout/Rfc5424Layout.java
+++ b/audit/src/main/java/org/apache/karaf/audit/layout/Rfc5424Layout.java
@@ -21,6 +21,8 @@ import org.apache.karaf.audit.util.Buffer;
 import org.apache.karaf.audit.util.FastDateFormat;
 
 import java.io.IOException;
+import java.util.Locale;
+import java.util.TimeZone;
 
 public class Rfc5424Layout extends AbstractLayout {
 
@@ -29,15 +31,15 @@ public class Rfc5424Layout extends AbstractLayout {
     protected final int facility;
     protected final int priority;
     protected final int enterpriseNumber;
+    protected final FastDateFormat fastDateFormat;
 
     protected String hdr1;
     protected String hdr2;
     protected String hdr3;
 
-    protected FastDateFormat fastDateFormat = new FastDateFormat();
-
-    public Rfc5424Layout(int facility, int priority, int enterpriseNumber) {
+    public Rfc5424Layout(int facility, int priority, int enterpriseNumber, 
TimeZone timeZone) {
         super(new Buffer(Buffer.Format.Syslog));
+        this.fastDateFormat = new FastDateFormat(timeZone, Locale.ENGLISH);
         this.facility = facility;
         this.priority = priority;
         this.enterpriseNumber = enterpriseNumber;
diff --git a/audit/src/test/java/org/apache/karaf/audit/TestPerf.java 
b/audit/src/test/java/org/apache/karaf/audit/TestPerf.java
index c2e1efe..51ca544 100644
--- a/audit/src/test/java/org/apache/karaf/audit/TestPerf.java
+++ b/audit/src/test/java/org/apache/karaf/audit/TestPerf.java
@@ -30,7 +30,9 @@ import java.io.Writer;
 import java.nio.charset.StandardCharsets;
 import java.util.Formatter;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
+import java.util.TimeZone;
 import java.util.concurrent.Callable;
 
 @Ignore
@@ -122,7 +124,7 @@ public class TestPerf {
         map.put("params", new Object[] { new 
ObjectName("org.apache.karaf.Mbean:type=foo"), "myMethod", new Object[] { 
String.class.getName() }, new String[] { "the-param "}});
         Event event = new MapEvent(map);
 
-        EventLayout layout = new Rfc3164Layout(16, 5, 
Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER);
+        EventLayout layout = new Rfc3164Layout(16, 5, 
Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER, TimeZone.getTimeZone("CET"), 
Locale.ENGLISH);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         Writer writer = new BufferedWriter(new OutputStreamWriter(baos, 
StandardCharsets.UTF_8));
 
diff --git 
a/audit/src/test/java/org/apache/karaf/audit/logger/EventLoggerTest.java 
b/audit/src/test/java/org/apache/karaf/audit/logger/EventLoggerTest.java
index f33d88f..c8959b5 100644
--- a/audit/src/test/java/org/apache/karaf/audit/logger/EventLoggerTest.java
+++ b/audit/src/test/java/org/apache/karaf/audit/logger/EventLoggerTest.java
@@ -40,7 +40,9 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
+import java.util.TimeZone;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
@@ -80,7 +82,7 @@ public class EventLoggerTest {
 
         Thread.sleep(100);
 
-        EventLayout layout = new Rfc3164Layout(16, 5, 
Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER);
+        EventLayout layout = new Rfc3164Layout(16, 5, 
Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER, TimeZone.getTimeZone("CET"), 
Locale.ENGLISH);
         EventLogger logger = new UdpEventLogger("localhost", port, "UTF-8", 
layout);
         logger.write(event);
 
@@ -123,7 +125,7 @@ public class EventLoggerTest {
 
         Thread.sleep(100);
 
-        EventLayout layout = new Rfc5424Layout(16, 5, 
Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER);
+        EventLayout layout = new Rfc5424Layout(16, 5, 
Rfc5424Layout.DEFAULT_ENTERPRISE_NUMBER, TimeZone.getTimeZone("CET"));
         EventLogger logger = new TcpEventLogger("localhost", port, "UTF-8", 
layout);
         logger.write(event);
         logger.flush();

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to