This is an automated email from the ASF dual-hosted git repository.

ladyvader pushed a commit to branch feature/GEODE-4909
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 647a004e6093c9ae064d773be2a5c0209608f69e
Author: Lynn Hughes-Godfrey <lhughesgodf...@pivotal.io>
AuthorDate: Tue Mar 27 15:23:07 2018 -0700

    GEODE-4909: Additional lucene reindex tests with security
    
    * Extended existing tests with and without gfsh to create region prior to 
creating lucene index.
---
 .../lucene/LuceneClientSecurityDUnitTest.java      | 19 +++--
 ...urityWithRegionCreatedBeforeIndexDUnitTest.java | 64 +++++++++++++++++
 .../lucene/LuceneCommandsSecurityDUnitTest.java    |  8 +--
 ...urityWithRegionCreatedBeforeIndexDUnitTest.java | 84 ++++++++++++++++++++++
 4 files changed, 161 insertions(+), 14 deletions(-)

diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityDUnitTest.java
index 0ae60a9..06cf7c1 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityDUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityDUnitTest.java
@@ -21,8 +21,6 @@ import static 
org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANA
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 import java.util.List;
@@ -31,7 +29,6 @@ import java.util.concurrent.TimeUnit;
 
 import junitparams.JUnitParamsRunner;
 import junitparams.Parameters;
-import org.assertj.core.api.Assertions;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
@@ -43,7 +40,6 @@ import org.apache.geode.cache.client.ClientCache;
 import org.apache.geode.cache.client.ClientCacheFactory;
 import org.apache.geode.cache.client.ClientRegionShortcut;
 import org.apache.geode.cache.client.ServerOperationException;
-import org.apache.geode.cache.lucene.test.TestObject;
 import org.apache.geode.cache.server.CacheServer;
 import org.apache.geode.distributed.ConfigurationProperties;
 import org.apache.geode.security.NotAuthorizedException;
@@ -63,6 +59,7 @@ public class LuceneClientSecurityDUnitTest extends 
LuceneQueriesAccessorBase {
       LuceneCommandsSecurityDUnitTest.UserNameAndExpectedResponse user) {
     // Start server
     int serverPort = dataStore1.invoke(() -> startCacheServer());
+    dataStore1.invoke(() -> createRegionIndexAndData());
 
     // Start client
     accessor.invoke(() -> startClient(user.getUserName(), serverPort));
@@ -72,6 +69,14 @@ public class LuceneClientSecurityDUnitTest extends 
LuceneQueriesAccessorBase {
         () -> executeTextSearch(user.getExpectAuthorizationError(), 
user.getExpectedResponse()));
   }
 
+  protected void createRegionIndexAndData() {
+    Cache cache = getCache();
+    LuceneService luceneService = LuceneServiceProvider.get(cache);
+    luceneService.createIndexFactory().addField("field1").create(INDEX_NAME, 
REGION_NAME);
+    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
+    region.put("key", new 
org.apache.geode.cache.lucene.test.TestObject("hello", "world"));
+  }
+
   private int startCacheServer() throws IOException {
     Properties props = new Properties();
     props.put(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER,
@@ -81,12 +86,6 @@ public class LuceneClientSecurityDUnitTest extends 
LuceneQueriesAccessorBase {
     final CacheServer server = cache.addCacheServer();
     server.setPort(0);
     server.start();
-    LuceneService luceneService = LuceneServiceProvider.get(cache);
-    luceneService.createIndexFactory().addField("field1").create(INDEX_NAME, 
REGION_NAME);
-    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
-
-    region.put("key", new 
org.apache.geode.cache.lucene.test.TestObject("hello", "world"));
-
     return server.getPort();
   }
 
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityWithRegionCreatedBeforeIndexDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityWithRegionCreatedBeforeIndexDUnitTest.java
new file mode 100644
index 0000000..7afcb36
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneClientSecurityWithRegionCreatedBeforeIndexDUnitTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+package org.apache.geode.cache.lucene;
+
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.INDEX_NAME;
+import static 
org.apache.geode.cache.lucene.test.LuceneTestUtilities.REGION_NAME;
+
+import junitparams.JUnitParamsRunner;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneIndexFactoryImpl;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.SecurityTest;
+
+@Category({DistributedTest.class, SecurityTest.class})
+@RunWith(JUnitParamsRunner.class)
+public class LuceneClientSecurityWithRegionCreatedBeforeIndexDUnitTest
+    extends LuceneClientSecurityDUnitTest {
+
+  @Before
+  public void setLuceneReindexFlag() {
+    dataStore1.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    dataStore2.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+    accessor.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    dataStore1.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+    dataStore2.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+    accessor.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+  }
+
+  @Override
+  protected void createRegionIndexAndData() {
+    Cache cache = getCache();
+    Region region = 
cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
+
+    region.put("key", new 
org.apache.geode.cache.lucene.test.TestObject("hello", "world"));
+
+    LuceneService luceneService = LuceneServiceProvider.get(cache);
+    ((LuceneIndexFactoryImpl) 
luceneService.createIndexFactory()).addField("field1")
+        .create(INDEX_NAME, REGION_NAME, LuceneServiceImpl.LUCENE_REINDEX);
+  }
+}
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneCommandsSecurityDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneCommandsSecurityDUnitTest.java
index be99c15..01258bc 100644
--- 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneCommandsSecurityDUnitTest.java
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneCommandsSecurityDUnitTest.java
@@ -57,7 +57,7 @@ public class LuceneCommandsSecurityDUnitTest {
   @Rule
   public GfshCommandRule gfshShell = new GfshCommandRule();
 
-  private MemberVM locator;
+  protected MemberVM locator;
 
   @Before
   public void before() throws Exception {
@@ -192,7 +192,7 @@ public class LuceneCommandsSecurityDUnitTest {
     verifyResult(user, result);
   }
 
-  private void createIndexAndRegion() throws Exception {
+  protected void createIndexAndRegion() throws Exception {
     // Connect gfsh to locator with permissions necessary to create an index 
and region
     this.gfshShell.secureConnectAndVerify(this.locator.getPort(), 
GfshCommandRule.PortType.locator,
         "cluster,data", "cluster,data");
@@ -218,7 +218,7 @@ public class LuceneCommandsSecurityDUnitTest {
     
assertTrue(this.gfshShell.getGfshOutput().contains(user.getExpectedResponse()));
   }
 
-  private String getCreateIndexCommand() {
+  protected String getCreateIndexCommand() {
     CommandStringBuilder csb = new 
CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
     csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
@@ -226,7 +226,7 @@ public class LuceneCommandsSecurityDUnitTest {
     return csb.toString();
   }
 
-  private String getCreateRegionCommand() {
+  protected String getCreateRegionCommand() {
     CommandStringBuilder csb = new 
CommandStringBuilder(CliStrings.CREATE_REGION);
     csb.addOption(CliStrings.CREATE_REGION__REGION, REGION_NAME);
     csb.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT,
diff --git 
a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneCommandsSecurityWithRegionCreatedBeforeIndexDUnitTest.java
 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneCommandsSecurityWithRegionCreatedBeforeIndexDUnitTest.java
new file mode 100644
index 0000000..cf285a8
--- /dev/null
+++ 
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneCommandsSecurityWithRegionCreatedBeforeIndexDUnitTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+package org.apache.geode.cache.lucene;
+
+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.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.lucene.internal.cli.LuceneCliStrings;
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.management.internal.cli.result.ErrorResultData;
+import org.apache.geode.management.internal.cli.result.ResultBuilder;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.security.SimpleTestSecurityManager;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.LuceneTest;
+import org.apache.geode.test.junit.categories.SecurityTest;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+
+@Category({DistributedTest.class, SecurityTest.class, LuceneTest.class})
+@RunWith(JUnitParamsRunner.class)
+public class LuceneCommandsSecurityWithRegionCreatedBeforeIndexDUnitTest
+    extends LuceneCommandsSecurityDUnitTest {
+
+  @Before
+  public void setLuceneReindexFlag() {
+    MemberVM server = this.locatorServer.getMember(1);
+    server.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = true);
+  }
+
+  @After
+  public void clearLuceneReindexFlag() {
+    MemberVM server = this.locatorServer.getMember(1);
+    server.invoke(() -> LuceneServiceImpl.LUCENE_REINDEX = false);
+  }
+
+  @Override
+  protected void createIndexAndRegion() throws Exception {
+    // Connect gfsh to locator with permissions necessary to create an index 
and region
+    this.gfshShell.secureConnectAndVerify(this.locator.getPort(), 
GfshCommandRule.PortType.locator,
+        "cluster,data", "cluster,data");
+
+    // Create region
+    
this.gfshShell.executeAndAssertThat(getCreateRegionCommand()).statusIsSuccess();
+
+    // Create lucene index
+    
this.gfshShell.executeAndAssertThat(getCreateIndexCommand()).statusIsSuccess();
+
+    // Disconnect gfsh
+    this.gfshShell.disconnect();
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
ladyva...@apache.org.

Reply via email to