summaryrefslogtreecommitdiff
path: root/test/java
diff options
context:
space:
mode:
authorluccioman <luccioman@users.noreply.github.com>2018-06-29 15:49:55 +0200
committerluccioman <luccioman@users.noreply.github.com>2018-06-29 15:49:55 +0200
commitf895745e1cd0dea933e73cd779f749a2224d583d (patch)
treece61e57920fb408b0ab12727ee9eadd3c94bd613 /test/java
parent5c6c61809a0d71a852668de75a87880079499d9a (diff)
Removed more unsafe concurrent accesses to SimpleDateFormat instances.
SimpleDateFormat must not be used by concurrent threads without synchronization for parsing or formating dates as it is not thread-safe (internally holds a calendar instance that is not synchronized). Prefer now DateTimeFormatter when possible as it is thread-safe without concurrent access performance bottleneck (does not internally use synchronization locks).
Diffstat (limited to 'test/java')
-rw-r--r--test/java/net/yacy/cora/protocol/HeaderFrameworkTest.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/java/net/yacy/cora/protocol/HeaderFrameworkTest.java b/test/java/net/yacy/cora/protocol/HeaderFrameworkTest.java
index 71d013698..971dc57ad 100644
--- a/test/java/net/yacy/cora/protocol/HeaderFrameworkTest.java
+++ b/test/java/net/yacy/cora/protocol/HeaderFrameworkTest.java
@@ -1,6 +1,29 @@
+// HeaderFrameworkTest.java
+// Copyright 2006-2018 by theli, f1ori, Michael Peter Christen; mc@yacy.net, reger; reger18@arcor.de, luccioman; https://github.com/luccioman
+//
+// This is a part of YaCy, a peer-to-peer based web search engine
+//
+// LICENSE
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
package net.yacy.cora.protocol;
+import java.time.Instant;
import java.util.Date;
+
import junit.framework.TestCase;
import org.junit.Test;
@@ -18,6 +41,22 @@ public class HeaderFrameworkTest extends TestCase {
// Print Result
System.out.println("testParseHTTPDate: " + parsedDate.toString());
+
+ parsedDate = HeaderFramework.parseHTTPDate("Monday, 12-Nov-07 10:11:12 GMT");
+
+ // returned date must not be null
+ assertNotNull(parsedDate);
+
+ // Print Result
+ System.out.println("testParseHTTPDate: " + parsedDate.toString());
+
+ parsedDate = HeaderFramework.parseHTTPDate("Mon Nov 12 10:11:12 2007");
+
+ // returned date must not be null
+ assertNotNull(parsedDate);
+
+ // Print Result
+ System.out.println("testParseHTTPDate: " + parsedDate.toString());
}
/**
@@ -31,4 +70,16 @@ public class HeaderFrameworkTest extends TestCase {
assertEquals("utf-8", HeaderFramework.getCharacterEncoding("Text/HTML;Charset=\"utf-8\""));
assertEquals("utf-8", HeaderFramework.getCharacterEncoding("text/html; charset=\"utf-8\""));
}
+
+ /**
+ * Unit test for date formatting with RFC 1123 format
+ */
+ @Test
+ public void testFormatRfc1123() {
+ assertEquals("", HeaderFramework.formatRFC1123(null));
+
+ final Instant time = Instant.parse("2018-06-29T13:04:55.00Z");
+ assertEquals("Fri, 29 Jun 2018 13:04:55 +0000", HeaderFramework.formatRFC1123(time.toEpochMilli()));
+ assertEquals("Fri, 29 Jun 2018 13:04:55 +0000", HeaderFramework.formatRFC1123(Date.from(time)));
+ }
}