[hibernate-commits] Hibernate SVN: r11408 - in trunk/HibernateExt/shards/src: test/org/hibernate/shards/strategy/exit and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Apr 17 01:53:37 EDT 2007


Author: max.ross
Date: 2007-04-17 01:53:37 -0400 (Tue, 17 Apr 2007)
New Revision: 11408

Added:
   trunk/HibernateExt/shards/src/test/org/hibernate/shards/strategy/exit/FirstNonNullResultExitStrategyTest.java
Modified:
   trunk/HibernateExt/shards/src/java/org/hibernate/shards/strategy/exit/FirstNonNullResultExitStrategy.java
Log:
fix bug HSHARDS-8, don't pass a null Shard to the ExitStrategy.

Modified: trunk/HibernateExt/shards/src/java/org/hibernate/shards/strategy/exit/FirstNonNullResultExitStrategy.java
===================================================================
--- trunk/HibernateExt/shards/src/java/org/hibernate/shards/strategy/exit/FirstNonNullResultExitStrategy.java	2007-04-16 19:16:51 UTC (rev 11407)
+++ trunk/HibernateExt/shards/src/java/org/hibernate/shards/strategy/exit/FirstNonNullResultExitStrategy.java	2007-04-17 05:53:37 UTC (rev 11408)
@@ -19,6 +19,7 @@
 package org.hibernate.shards.strategy.exit;
 
 import org.hibernate.shards.Shard;
+import org.hibernate.shards.util.Preconditions;
 
 /**
  * Threadsafe ExitStrategy implementation that only accepts the first result
@@ -36,6 +37,7 @@
    * will have its result reflected.
    */
   public final synchronized boolean addResult(T result, Shard shard) {
+    Preconditions.checkNotNull(shard);
     if(result != null && nonNullResult == null) {
       nonNullResult = result;
       this.shard = shard;
@@ -47,4 +49,8 @@
   public T compileResults(ExitOperationsCollector exitOperationsCollector) {
     return nonNullResult;
   }
+
+  public Shard getShardOfResult() {
+    return shard;
+  }
 }

Added: trunk/HibernateExt/shards/src/test/org/hibernate/shards/strategy/exit/FirstNonNullResultExitStrategyTest.java
===================================================================
--- trunk/HibernateExt/shards/src/test/org/hibernate/shards/strategy/exit/FirstNonNullResultExitStrategyTest.java	                        (rev 0)
+++ trunk/HibernateExt/shards/src/test/org/hibernate/shards/strategy/exit/FirstNonNullResultExitStrategyTest.java	2007-04-17 05:53:37 UTC (rev 11408)
@@ -0,0 +1,59 @@
+/**
+ * Copyright (C) 2007 Google Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+package org.hibernate.shards.strategy.exit;
+
+import junit.framework.TestCase;
+
+import org.hibernate.shards.Shard;
+import org.hibernate.shards.ShardDefaultMock;
+
+/**
+ * @author maxr at google.com (Max Ross)
+ */
+public class FirstNonNullResultExitStrategyTest extends TestCase {
+
+  public void testNullShard() {
+    FirstNonNullResultExitStrategy<Object> fnnres = new FirstNonNullResultExitStrategy<Object>();
+    try {
+      fnnres.addResult(null, null);
+      fail("expected npe");
+    } catch (NullPointerException npe) {
+      // good
+    }
+  }
+
+  public void testAddResult() {
+    FirstNonNullResultExitStrategy<Object> fnnres = new FirstNonNullResultExitStrategy<Object>();
+    Shard shard1 = new ShardDefaultMock();
+    fnnres.addResult(null, shard1);
+    assertNull(fnnres.compileResults(null));
+    assertNull(fnnres.getShardOfResult());
+
+    Object result = new Object();
+    Shard shard2 = new ShardDefaultMock();
+    fnnres.addResult(result, shard2);
+    assertSame(result, fnnres.compileResults(null));
+    assertSame(shard2, fnnres.getShardOfResult());
+
+    Object anotherResult = new Object();
+    Shard shard3 = new ShardDefaultMock();
+    fnnres.addResult(anotherResult, shard3);
+    assertSame(result, fnnres.compileResults(null));
+    assertSame(shard2, fnnres.getShardOfResult());
+  }
+}




More information about the hibernate-commits mailing list