hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r793186 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/impl/nio/reactor/ExceptionEvent.java test/java/org/apache/http/impl/nio/reactor/ExceptionEventTest.java
Date Sat, 11 Jul 2009 15:38:56 GMT
Author: olegk
Date: Sat Jul 11 15:38:56 2009
New Revision: 793186

URL: http://svn.apache.org/viewvc?rev=793186&view=rev
Log:
HTTPCORE-187: ExceptionEvent - clone Date to ensure immutable state

Contributed by Nathan Beyer <ndbeyer at apache.org>

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ExceptionEventTest.java
  (with props)
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ExceptionEvent.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ExceptionEvent.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ExceptionEvent.java?rev=793186&r1=793185&r2=793186&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ExceptionEvent.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ExceptionEvent.java
Sat Jul 11 15:38:56 2009
@@ -41,12 +41,16 @@
 public class ExceptionEvent {
 
     private final Throwable ex;
-    private final Date timestamp;
+    private final long time;
     
     public ExceptionEvent(final Throwable ex, final Date timestamp) {
         super();
         this.ex = ex;
-        this.timestamp = timestamp;
+        if (timestamp != null) {
+            this.time = timestamp.getTime(); 
+        } else {
+            this.time = 0;
+        }
     }
     
     public ExceptionEvent(final Exception ex) {
@@ -58,13 +62,13 @@
     }
 
     public Date getTimestamp() {
-        return timestamp;
+        return new Date(this.time);
     }
 
     @Override
     public String toString() {
         StringBuilder buffer = new StringBuilder();
-        buffer.append(this.timestamp);
+        buffer.append(new Date(this.time));
         buffer.append(" ");
         buffer.append(this.ex);
         return buffer.toString();

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ExceptionEventTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ExceptionEventTest.java?rev=793186&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ExceptionEventTest.java
(added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ExceptionEventTest.java
Sat Jul 11 15:38:56 2009
@@ -0,0 +1,56 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.nio.reactor;
+
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+public class ExceptionEventTest extends TestCase {
+
+    public void testGetCause() {
+        NullPointerException npe = new NullPointerException("npe");
+        ExceptionEvent ee = new ExceptionEvent(npe);
+        assertSame(npe, ee.getCause());
+        ee = new ExceptionEvent(npe, new Date());
+        assertSame(npe, ee.getCause());
+    }
+
+    public void testGetTimestamp() {
+        NullPointerException npe = new NullPointerException("npe");
+        ExceptionEvent ee = new ExceptionEvent(npe);
+        assertNotNull(ee.getTimestamp());
+        ee = new ExceptionEvent(npe, new Date(1234567890L));
+        assertEquals(new Date(1234567890L), ee.getTimestamp());
+    }
+
+    public void testToString() {
+        assertNotNull(new ExceptionEvent(new NullPointerException()));
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ExceptionEventTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ExceptionEventTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ExceptionEventTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message