You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2015/07/09 10:53:11 UTC

svn commit: r1690031 - /lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestDateUtil.java

Author: uschindler
Date: Thu Jul  9 08:53:11 2015
New Revision: 1690031

URL: http://svn.apache.org/r1690031
Log:
Add a testcase for DateUtil to debug the recent Java 9 failures (may be extended)

Added:
    lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestDateUtil.java   (with props)

Added: lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestDateUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestDateUtil.java?rev=1690031&view=auto
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestDateUtil.java (added)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/common/util/TestDateUtil.java Thu Jul  9 08:53:11 2015
@@ -0,0 +1,41 @@
+package org.apache.solr.common.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.text.ParseException;
+import java.util.Date;
+
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestDateUtil extends LuceneTestCase {
+
+  public void testCurrentTime() throws ParseException {
+    long now = System.currentTimeMillis();
+    assertParsedDate(now, new Date(now).toString(), 1000L);
+  }
+  
+  public void testParseDate() throws ParseException {
+    assertParsedDate(1226583351000L, "Thu Nov 13 04:35:51 AKST 2008", 0L);
+  }
+    
+  private static void assertParsedDate(long ts, String dateStr, long epsilon) throws ParseException {
+    System.out.println(DateUtil.parseDate(dateStr).getTime());
+    assertTrue("Incorrect parsed timestamp", Math.abs(ts - DateUtil.parseDate(dateStr).getTime()) <= epsilon);
+  }
+
+}