GEODE-2958: Destroying a defined index now removes the RegionListener

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

Branch: refs/heads/feature/GEODE-2632-17
Commit: 662358fdba33ce2ea99cadfe07303361b26ead56
Parents: dff937f
Author: Barry Oglesby <bogle...@pivotal.io>
Authored: Tue May 23 17:27:01 2017 -0700
Committer: Barry Oglesby <bogle...@pivotal.io>
Committed: Wed May 24 10:06:50 2017 -0700

----------------------------------------------------------------------
 .../lucene/internal/LuceneServiceImpl.java      |  3 +
 .../lucene/LuceneIndexDestroyDUnitTest.java     | 39 +++++++++--
 .../LuceneDestroyIndexFunctionJUnitTest.java    | 72 ++++++++++++--------
 3 files changed, 79 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/662358fd/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
index ebee59e..afbcc40 100644
--- 
a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
+++ 
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
@@ -232,6 +232,9 @@ public class LuceneServiceImpl implements 
InternalLuceneService {
   }
 
   public void destroyDefinedIndex(String indexName, String regionPath) {
+    if (!regionPath.startsWith("/")) {
+      regionPath = "/" + regionPath;
+    }
     String uniqueIndexName = LuceneServiceImpl.getUniqueIndexName(indexName, 
regionPath);
     if (definedIndexMap.containsKey(uniqueIndexName)) {
       definedIndexMap.remove(uniqueIndexName);

http://git-wip-us.apache.org/repos/asf/geode/blob/662358fd/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
----------------------------------------------------------------------
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
index a6252c8..b34d998 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexDestroyDUnitTest.java
@@ -401,7 +401,7 @@ public class LuceneIndexDestroyDUnitTest extends 
LuceneDUnitTest {
 
     // Recreate index and region
     String newIndexName = INDEX_NAME + "+_1";
-    SerializableRunnableIF createIndexNewName = createIndex(newIndexName, 
"field1");
+    SerializableRunnableIF createIndexNewName = createIndex(newIndexName, 
REGION_NAME, "field1");
     dataStore1.invoke(() -> initDataStore(createIndexNewName, regionType));
     dataStore2.invoke(() -> initDataStore(createIndexNewName, regionType));
     accessor.invoke(() -> initAccessor(createIndexNewName, regionType));
@@ -455,7 +455,7 @@ public class LuceneIndexDestroyDUnitTest extends 
LuceneDUnitTest {
     dataStore1.invoke(() -> destroyDataRegion(true));
 
     // Create new index and region
-    SerializableRunnableIF createNewIndex = createIndex(INDEX_NAME, "field2");
+    SerializableRunnableIF createNewIndex = createIndex(INDEX_NAME, 
REGION_NAME, "field2");
     dataStore1.invoke(() -> initDataStore(createNewIndex, regionType));
     dataStore2.invoke(() -> initDataStore(createNewIndex, regionType));
     accessor.invoke(() -> initAccessor(createNewIndex, regionType));
@@ -472,14 +472,26 @@ public class LuceneIndexDestroyDUnitTest extends 
LuceneDUnitTest {
     accessor.invoke(() -> executeQuery(INDEX_NAME, "field2Value", "field2", 
numPuts));
   }
 
+  @Test
+  @Parameters(method = "getListOfRegionTestTypes")
+  public void verifyCreateDestroyDefinedIndex(RegionTestableType regionType) {
+    String[] regionNames = {REGION_NAME, "/" + REGION_NAME};
+    for (String regionName : regionNames) {
+      dataStore1.invoke(createIndex(INDEX_NAME, regionName, "field1"));
+      dataStore1.invoke(() -> verifyDefinedIndexCreated(INDEX_NAME, 
regionName));
+      dataStore1.invoke(() -> destroyDefinedIndex(INDEX_NAME, regionName));
+      dataStore1.invoke(() -> verifyDefinedIndexDestroyed(INDEX_NAME, 
regionName));
+    }
+  }
+
   private SerializableRunnableIF createIndex() {
-    return createIndex(INDEX_NAME, "field1");
+    return createIndex(INDEX_NAME, REGION_NAME, "field1");
   }
 
-  private SerializableRunnableIF createIndex(String indexName, String field) {
+  private SerializableRunnableIF createIndex(String indexName, String 
regionName, String field) {
     return () -> {
       LuceneService luceneService = LuceneServiceProvider.get(getCache());
-      luceneService.createIndexFactory().setFields(field).create(indexName, 
REGION_NAME);
+      luceneService.createIndexFactory().setFields(field).create(indexName, 
regionName);
     };
   }
 
@@ -502,6 +514,18 @@ public class LuceneIndexDestroyDUnitTest extends 
LuceneDUnitTest {
     assertNotNull(luceneService.getIndex(INDEX2_NAME, REGION_NAME));
   }
 
+  private void verifyDefinedIndexCreated(String indexName, String regionName) {
+    LuceneServiceImpl luceneService = (LuceneServiceImpl) 
LuceneServiceProvider.get(getCache());
+    assertNotNull(luceneService.getDefinedIndex(indexName, regionName));
+    assertEquals(1, getCache().getRegionListeners().size());
+  }
+
+  private void verifyDefinedIndexDestroyed(String indexName, String 
regionName) {
+    LuceneServiceImpl luceneService = (LuceneServiceImpl) 
LuceneServiceProvider.get(getCache());
+    assertNull(luceneService.getDefinedIndex(indexName, regionName));
+    assertEquals(0, getCache().getRegionListeners().size());
+  }
+
   private void waitUntilFlushed(String indexName) throws Exception {
     LuceneService luceneService = LuceneServiceProvider.get(getCache());
     assertTrue(
@@ -598,6 +622,11 @@ public class LuceneIndexDestroyDUnitTest extends 
LuceneDUnitTest {
     luceneService.destroyIndex(INDEX_NAME, REGION_NAME);
   }
 
+  private void destroyDefinedIndex(String indexName, String regionName) {
+    LuceneServiceImpl luceneService = (LuceneServiceImpl) 
LuceneServiceProvider.get(getCache());
+    luceneService.destroyDefinedIndex(indexName, regionName);
+  }
+
   private void destroyIndexes() {
     LuceneService luceneService = LuceneServiceProvider.get(getCache());
     luceneService.destroyIndexes(REGION_NAME);

http://git-wip-us.apache.org/repos/asf/geode/blob/662358fd/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunctionJUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunctionJUnitTest.java
index 1d2d773..ce0344d 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunctionJUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneDestroyIndexFunctionJUnitTest.java
@@ -56,58 +56,66 @@ public class LuceneDestroyIndexFunctionJUnitTest {
   @Test
   @SuppressWarnings("unchecked")
   public void testDestroyIndex() throws Throwable {
-    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo("index1", 
"/region1", false);
+    String indexName = "index1";
+    String regionPath = "/region1";
+    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(indexName, 
regionPath, false);
     when(this.context.getArguments()).thenReturn(indexInfo);
     LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
     function = spy(function);
     doReturn(this.cache).when(function).getCache();
     function.execute(this.context);
-    verify(this.service).destroyIndex(eq("index1"), eq("/region1"));
-    verify(function).getXmlEntity(eq("index1"), eq("/region1"));
-    verify(this.service, never()).destroyDefinedIndex(eq("index1"), 
eq("/region1"));
-    verify(this.service, never()).destroyIndexes(eq("/region1"));
+    verify(this.service).destroyIndex(eq(indexName), eq(regionPath));
+    verify(function).getXmlEntity(eq(indexName), eq(regionPath));
+    verify(this.service, never()).destroyDefinedIndex(eq(indexName), 
eq(regionPath));
+    verify(this.service, never()).destroyIndexes(eq(regionPath));
     verifyFunctionResult(true);
   }
 
   @Test
   @SuppressWarnings("unchecked")
   public void testDestroyIndexFailure() throws Throwable {
-    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo("index1", 
"/region1", false);
+    String indexName = "index1";
+    String regionPath = "/region1";
+    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(indexName, 
regionPath, false);
     when(this.context.getArguments()).thenReturn(indexInfo);
     LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
     function = spy(function);
     doReturn(this.cache).when(function).getCache();
-    doThrow(new 
IllegalStateException()).when(this.service).destroyIndex(eq("index1"),
-        eq("/region1"));
+    doThrow(new 
IllegalStateException()).when(this.service).destroyIndex(eq(indexName),
+        eq(regionPath));
     function.execute(this.context);
     verifyFunctionResult(false);
   }
 
   @Test
   public void testDestroyDefinedIndex() throws Throwable {
-    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo("index1", 
"/region1", true);
+    String indexName = "index1";
+    String regionPath = "/region1";
+    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(indexName, 
regionPath, true);
     when(this.context.getArguments()).thenReturn(indexInfo);
     LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
     function = spy(function);
     doReturn(this.cache).when(function).getCache();
     function.execute(this.context);
-    verify(this.service).destroyDefinedIndex(eq("index1"), eq("/region1"));
-    verify(this.service, never()).destroyIndex(eq("index1"), eq("/region1"));
-    verify(this.service, never()).destroyIndexes(eq("/region1"));
-    verify(function, never()).getXmlEntity(eq("index1"), eq("/region1"));
+    verify(this.service).destroyDefinedIndex(eq(indexName), eq(regionPath));
+    verify(this.service, never()).destroyIndex(eq(indexName), eq(regionPath));
+    verify(this.service, never()).destroyIndexes(eq(regionPath));
+    verify(function, never()).getXmlEntity(eq(indexName), eq(regionPath));
     verifyFunctionResult(true);
   }
 
   @Test
   @SuppressWarnings("unchecked")
   public void testDestroyDefinedIndexFailure() throws Throwable {
-    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo("index1", 
"/region1", true);
+    String indexName = "index1";
+    String regionPath = "/region1";
+    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(indexName, 
regionPath, true);
     when(this.context.getArguments()).thenReturn(indexInfo);
     LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
     function = spy(function);
     doReturn(this.cache).when(function).getCache();
-    doThrow(new 
IllegalStateException()).when(this.service).destroyDefinedIndex(eq("index1"),
-        eq("/region1"));
+    doThrow(new 
IllegalStateException()).when(this.service).destroyDefinedIndex(eq(indexName),
+        eq(regionPath));
     function.execute(this.context);
     verifyFunctionResult(false);
   }
@@ -115,28 +123,30 @@ public class LuceneDestroyIndexFunctionJUnitTest {
   @Test
   @SuppressWarnings("unchecked")
   public void testDestroyIndexes() throws Throwable {
-    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(null, 
"/region1", false);
+    String regionPath = "/region1";
+    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(null, 
regionPath, false);
     when(this.context.getArguments()).thenReturn(indexInfo);
     LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
     function = spy(function);
     doReturn(this.cache).when(function).getCache();
     function.execute(this.context);
-    verify(this.service).destroyIndexes(eq("/region1"));
-    verify(function).getXmlEntity(eq(null), eq("/region1"));
-    verify(this.service, never()).destroyDefinedIndexes(eq("/region1"));
-    verify(this.service, never()).destroyIndex(any(), eq("/region1"));
+    verify(this.service).destroyIndexes(eq(regionPath));
+    verify(function).getXmlEntity(eq(null), eq(regionPath));
+    verify(this.service, never()).destroyDefinedIndexes(eq(regionPath));
+    verify(this.service, never()).destroyIndex(any(), eq(regionPath));
     verifyFunctionResult(true);
   }
 
   @Test
   @SuppressWarnings("unchecked")
   public void testDestroyIndexesFailure() throws Throwable {
-    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(null, 
"/region1", false);
+    String regionPath = "/region1";
+    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(null, 
regionPath, false);
     when(this.context.getArguments()).thenReturn(indexInfo);
     LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
     function = spy(function);
     doReturn(this.cache).when(function).getCache();
-    doThrow(new 
IllegalStateException()).when(this.service).destroyIndexes(eq("/region1"));
+    doThrow(new 
IllegalStateException()).when(this.service).destroyIndexes(eq(regionPath));
     function.execute(this.context);
     verifyFunctionResult(false);
   }
@@ -144,28 +154,30 @@ public class LuceneDestroyIndexFunctionJUnitTest {
   @Test
   @SuppressWarnings("unchecked")
   public void testDestroyDefinedIndexes() throws Throwable {
-    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(null, 
"/region1", true);
+    String regionPath = "/region1";
+    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(null, 
regionPath, true);
     when(this.context.getArguments()).thenReturn(indexInfo);
     LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
     function = spy(function);
     doReturn(this.cache).when(function).getCache();
     function.execute(this.context);
-    verify(this.service).destroyDefinedIndexes(eq("/region1"));
-    verify(this.service, never()).destroyIndexes(eq("/region1"));
-    verify(this.service, never()).destroyIndex(any(), eq("/region1"));
-    verify(function, never()).getXmlEntity(eq("index1"), eq("/region1"));
+    verify(this.service).destroyDefinedIndexes(eq(regionPath));
+    verify(this.service, never()).destroyIndexes(eq(regionPath));
+    verify(this.service, never()).destroyIndex(any(), eq(regionPath));
+    verify(function, never()).getXmlEntity(eq("index1"), eq(regionPath));
     verifyFunctionResult(true);
   }
 
   @Test
   @SuppressWarnings("unchecked")
   public void testDestroyDefinedIndexesFailure() throws Throwable {
-    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(null, 
"/region1", true);
+    String regionPath = "/region1";
+    LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(null, 
regionPath, true);
     when(this.context.getArguments()).thenReturn(indexInfo);
     LuceneDestroyIndexFunction function = new LuceneDestroyIndexFunction();
     function = spy(function);
     doReturn(this.cache).when(function).getCache();
-    doThrow(new 
IllegalStateException()).when(this.service).destroyDefinedIndexes(eq("/region1"));
+    doThrow(new 
IllegalStateException()).when(this.service).destroyDefinedIndexes(eq(regionPath));
     function.execute(this.context);
     verifyFunctionResult(false);
   }

Reply via email to