geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasonhu...@apache.org
Subject [3/3] geode git commit: Modified test for client transactions with Lucene queries
Date Tue, 18 Apr 2017 16:22:34 GMT
Modified test for client transactions with Lucene queries


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/1bd2b86e
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/1bd2b86e
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/1bd2b86e

Branch: refs/heads/feature/GEODE-2703
Commit: 1bd2b86eecbedfcddb56e2298e49fb14a2cceaf3
Parents: 4642639
Author: Jason Huynh <huynhja@gmail.com>
Authored: Tue Apr 18 09:22:03 2017 -0700
Committer: Jason Huynh <huynhja@gmail.com>
Committed: Tue Apr 18 09:22:03 2017 -0700

----------------------------------------------------------------------
 .../cache/lucene/internal/LuceneQueryImpl.java  |  4 +-
 .../lucene/LuceneQueriesClientDUnitTest.java    | 42 +++++++++++++++-----
 .../cache/lucene/LuceneQueriesDUnitTest.java    |  3 +-
 3 files changed, 35 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/1bd2b86e/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
index d660608..bfc561a 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
@@ -120,14 +120,14 @@ public class LuceneQueryImpl<K, V> implements LuceneQuery<K,
V> {
       if (e.getCause() instanceof LuceneQueryException) {
         throw new LuceneQueryException(e);
       } else if (e.getCause() instanceof TransactionException) {
-        //When run from client with single hop disabled
+        // When run from client with single hop disabled
         throw new LuceneQueryException(LUCENE_QUERY_CANNOT_BE_EXECUTED_WITHIN_A_TRANSACTION);
       } else if (e.getCause() instanceof RuntimeException) {
         throw (RuntimeException) e.getCause();
       }
       throw e;
     } catch (TransactionException e) {
-      //When function execution is run from server
+      // When function execution is run from server
       throw new LuceneQueryException(LUCENE_QUERY_CANNOT_BE_EXECUTED_WITHIN_A_TRANSACTION);
     }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/1bd2b86e/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesClientDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesClientDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesClientDUnitTest.java
index b8868e9..0c4211d 100755
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesClientDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesClientDUnitTest.java
@@ -14,9 +14,13 @@
  */
 package org.apache.geode.cache.lucene;
 
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
+import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.INDEX_NAME;
 import static org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import org.apache.geode.cache.lucene.internal.LuceneQueryImpl;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -66,19 +70,37 @@ public class LuceneQueriesClientDUnitTest extends LuceneQueriesDUnitTest
{
     return new RegionTestableType[] {RegionTestableType.PARTITION_WITH_CLIENT};
   }
 
-  //Due to singlehop transactions differences, the exception actually isn't thrown
-  //So the parent test behaves differently if singlehop is enabled or not for a client
+  // Due to singlehop transactions differences, the exception actually isn't thrown
+  // So the parent test behaves differently if singlehop is enabled or not for a client
   public void transactionWithLuceneQueriesShouldThrowException(RegionTestableType regionTestType)
{
-    try {
-      super.transactionWithLuceneQueriesShouldThrowException(regionTestType);
-      fail();
-    }
-    catch (AssertionError e) {
-      //Expecting the parent test to fail because client transactions with single hop do
not fail with Lucene Querying at this point
-    }
+    SerializableRunnableIF createIndex = () -> {
+      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      luceneService.createIndexFactory().addField("text").create(INDEX_NAME, REGION_NAME);
+    };
+    dataStore1.invoke(() -> initDataStore(createIndex, regionTestType));
+    dataStore2.invoke(() -> initDataStore(createIndex, regionTestType));
+    accessor.invoke(() -> initAccessor(createIndex, regionTestType));
+
+    putDataInRegion(accessor);
+    assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
+    assertTrue(waitForFlushBeforeExecuteTextSearch(dataStore1, 60000));
+
+    accessor.invoke(() -> {
+      Cache cache = getCache();
+      try {
+        LuceneService service = LuceneServiceProvider.get(cache);
+        LuceneQuery<Integer, TestObject> query;
+        query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "text:world",
+            DEFAULT_FIELD);
+        cache.getCacheTransactionManager().begin();
+        PageableLuceneQueryResults<Integer, TestObject> results = query.findPages();
+      } finally {
+        cache.getCacheTransactionManager().rollback();
+      }
+    });
 
   }
 
 
 
-  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/1bd2b86e/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
index b405c85..c319a16 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneQueriesDUnitTest.java
@@ -78,8 +78,7 @@ public class LuceneQueriesDUnitTest extends LuceneQueriesAccessorBase {
             .equals(LuceneQueryImpl.LUCENE_QUERY_CANNOT_BE_EXECUTED_WITHIN_A_TRANSACTION))
{
           fail();
         }
-      }
-      finally {
+      } finally {
         cache.getCacheTransactionManager().rollback();
       }
     });


Mime
View raw message