You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by na...@apache.org on 2010/10/26 21:03:34 UTC

svn commit: r1027684 - in /tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src: main/java/org/apache/tuscany/sca/binding/atom/provider/ test/java/org/apache/tuscany/sca/binding/atom/

Author: nash
Date: Tue Oct 26 19:03:33 2010
New Revision: 1027684

URL: http://svn.apache.org/viewvc?rev=1027684&view=rev
Log:
TUSCANY-3742: Fix time comparison for If-Modified-Since and If-Unmodified-Since (merged 1.x commit r1027658)

Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
    tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java

Modified: tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java?rev=1027684&r1=1027683&r2=1027684&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java Tue Oct 26 19:03:33 2010
@@ -279,7 +279,7 @@ class AtomBindingListenerServlet extends
                     if ( predicate != null ) {
                         try {
                             Date predicateDate = dateFormat.parse( predicate ); 
-                            if ( predicateDate.compareTo( feedUpdated ) < 0 ) {
+                            if ( predicateDate.compareTo( exactSeconds(feedUpdated) ) < 0 ) {
                                 // Match, should short circuit
                                 response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                                 return;
@@ -292,7 +292,7 @@ class AtomBindingListenerServlet extends
                     if ( predicate != null ) {
                         try {
                             Date predicateDate = dateFormat.parse( predicate ); 
-                            if ( predicateDate.compareTo( feedUpdated ) > 0 ) {
+                            if ( predicateDate.compareTo( exactSeconds(feedUpdated) ) >= 0 ) {
                                 // Match, should short circuit
                                 response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                                 return;
@@ -891,5 +891,13 @@ class AtomBindingListenerServlet extends
         }
     }
 
-    
+    /**
+     * Round a date down to an exact number of seconds
+     * @param date with millisecond precision
+     * @return date rounded down to nearest second
+     */
+    private Date exactSeconds(Date date) {
+        return new Date(date.getTime() / 1000 * 1000);
+    }
+
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java?rev=1027684&r1=1027683&r2=1027684&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java Tue Oct 26 19:03:33 2010
@@ -175,7 +175,7 @@ public class ProviderFeedEntityTagsTestC
         }
     }		
 
-    // @Test @Ignore Intermitently fails, see TUSCANY-3299
+    @Test
     public void testUnmodifiedGetIfUnModified() throws Exception {		
         //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfUnModified");
         // Feed request with predicates
@@ -187,8 +187,9 @@ public class ProviderFeedEntityTagsTestC
         ClientResponse res = client.get(providerURI, opts);
         Assert.assertNotNull(res);
         try {
-            // Should return 304 - Feed not provided since feed is modified since.
-            Assert.assertEquals(304, res.getStatus());
+            // Should return 200 - Feed provided since feed is unmodified since.
+            Assert.assertEquals(200, res.getStatus());
+            Assert.assertEquals(ResponseType.SUCCESS, res.getType());
         } finally {
             res.release();
         }
@@ -276,7 +277,7 @@ public class ProviderFeedEntityTagsTestC
             Date thisLastModified = res.getLastModified();
             Assert.assertNotNull( thisLastModified );
 
-            // Should return 200 - value since feed is changed
+            // Should return 200 - value since feed matches eTag
             Assert.assertEquals(200, res.getStatus());
             Assert.assertEquals(ResponseType.SUCCESS, res.getType());
 
@@ -290,12 +291,12 @@ public class ProviderFeedEntityTagsTestC
 
     @Test
     public void testModifiedGetIfUnModified() throws Exception {		
-        //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfUnModified");
+        //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfUnModified");
         // Feed request with predicates
         RequestOptions opts = new RequestOptions();
         final String contentType = "application/atom+xml"; 
         opts.setContentType(contentType);
-        opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() ));
+        opts.setHeader( "If-Unmodified-Since", dateFormat.format( previousSecond(lastModified) ));
 
         ClientResponse res = client.get(providerURI, opts);
         Assert.assertNotNull(res);
@@ -309,12 +310,12 @@ public class ProviderFeedEntityTagsTestC
 
     @Test
     public void testModifiedGetIfModified() throws Exception {		
-        //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfModified");
+        //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfModified");
         // Feed request with predicates
         RequestOptions opts = new RequestOptions();
         final String contentType = "application/atom+xml"; 
         opts.setContentType(contentType);
-        opts.setHeader( "If-Modified-Since", dateFormat.format( lastModified ));
+        opts.setHeader( "If-Modified-Since", dateFormat.format( previousSecond(lastModified) ));
 
         ClientResponse res = client.get(providerURI, opts);
         Assert.assertNotNull(res);
@@ -383,4 +384,13 @@ public class ProviderFeedEntityTagsTestC
             }
         }
     }
+
+    /**
+     * Subtract one second from a date
+     * @param date with millisecond precision
+     * @return date with one second subtracted
+     */
+    private Date previousSecond(Date date) {
+        return new Date(date.getTime() - 1000);
+    }
 }