You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2020/08/07 20:08:04 UTC
[GitHub] [geode] jinmeiliao opened a new pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
jinmeiliao opened a new pull request #5436:
URL: https://github.com/apache/geode/pull/5436
* allow ClusterStartupRule to launch dunit default locator
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] jinmeiliao commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
jinmeiliao commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r469576684
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(2, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ private ClientCache clientCache;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(0, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ }
+
+ @Test
+ public void verifyQuerySucceedsAfterClear() throws Exception {
+ Region cities = clientCacheRule.createProxyRegion("cities");
+ // put in some data
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(100);
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(50);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(1);
+
+ cities.clear();
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(0);
+ }, server1, server2);
+
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
+
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion("cities");
+ Index cityId = qs.getIndex(region, "cityId");
+ IndexStatistics statistics = cityId.getStatistics();
+ assertThat(statistics.getNumberOfKeys()).isEqualTo(0);
+ assertThat(statistics.getNumberOfValues()).isEqualTo(0);
+ Index cityName = qs.getIndex(region, "cityName");
+ IndexStatistics statistics1 = cityName.getStatistics();
+ assertThat(statistics1.getNumberOfKeys()).isEqualTo(0);
+ assertThat(statistics1.getNumberOfValues()).isEqualTo(0);
+ }, server1, server2);
+ }
+
+ @Test
+ public void concurrentClearAndQuery() {
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+
+ server1.invokeAsync(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ IntStream.range(0, 100).forEach(i -> region.put(i, new City(i)));
+ region.clear();
+ });
+
+ await().pollDelay(5, TimeUnit.MILLISECONDS).untilAsserted(() -> {
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
Review comment:
yes, it will keep on executing the query until it's returning 0 results.
There is a slight chance that this could get executed even before the region is populated, that's why I put a pollDelay there to reduce this chance.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] jinmeiliao commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
jinmeiliao commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r479357437
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,369 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.junit.rules.VMProvider.invokeInEveryMember;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ServerOperationException;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.DUnitBlackboard;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(4, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ private static DUnitBlackboard blackboard;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ @Rule
+ public ExecutorServiceRule executor = ExecutorServiceRule.builder().build();
+
+ private ClientCache clientCache;
+ private Region cities;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(2, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
Review comment:
I believe even with just one iteration, it's still a range index. There are only 2 kinds of index now: range or key. Hash is deprecated.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp commented on pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
mhansonp commented on pull request #5436:
URL: https://github.com/apache/geode/pull/5436#issuecomment-685193313
I made some updates on mhansonp minorcleanup to resolve warnings.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] jinmeiliao commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
jinmeiliao commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r479359658
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,369 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.junit.rules.VMProvider.invokeInEveryMember;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ServerOperationException;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.DUnitBlackboard;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(4, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ private static DUnitBlackboard blackboard;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ @Rule
+ public ExecutorServiceRule executor = ExecutorServiceRule.builder().build();
+
+ private ClientCache clientCache;
+ private Region cities;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(2, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ cities = clientCacheRule.createProxyRegion("cities");
+ }
+
+ @Test
+ public void clearOnEmptyRegion() throws Exception {
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear();
+ }, server1, server2);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear();
+ }, server1, server2);
+ }
+
+ @Test
+ public void createIndexWhileClear() throws Exception {
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear at the same time
+ cities.clear();
Review comment:
I would prefer not to use testHooks if I can help it. I increased the region size to 1000 and do clear for multiple times to increase the chance of concurrency.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
mhansonp commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r481498183
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,374 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.junit.rules.VMProvider.invokeInEveryMember;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ServerOperationException;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.DUnitBlackboard;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(4, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ private static DUnitBlackboard blackboard;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ @Rule
+ public ExecutorServiceRule executor = ExecutorServiceRule.builder().build();
+
+ private ClientCache clientCache;
+ private Region cities;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(2, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ cities = clientCacheRule.createProxyRegion("cities");
+ }
+
+ @Test
+ public void clearOnEmptyRegion() throws Exception {
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+ }
+
+ @Test
+ public void createIndexWhileClear() throws Exception {
+ IntStream.range(0, 1000).forEach(i -> cities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear for 3 times at the same time to increease the concurrency of clear and createIndex
+ for (int i = 0; i < 3; i++) {
+ cities.clear();
+ }
+ createIndex.await();
+
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query =
+ queryService.newQuery("select * from /cities c where c.zip < " + (City.ZIP_START + 10));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(10);
+ }
+
+ @Test
+ public void createIndexWhileClearOnReplicateRegion() throws Exception {
+ invokeInEveryMember(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ cache.createRegionFactory(RegionShortcut.PARTITION)
+ .create("replicateCities");
+ }, server1, server2);
+
+ Region replicateCities = clientCacheRule.createProxyRegion("replicateCities");
+ IntStream.range(0, 1000).forEach(i -> replicateCities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index on replicate regions", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip_replicate", "c.zip", "/replicateCities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear at the same time for 3 timese
+ for (int i = 0; i < 3; i++) {
+ replicateCities.clear();
+ }
+ createIndex.await();
+
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("replicateCities", "cityZip_replicate");
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query =
+ queryService
+ .newQuery("select * from /replicateCities c where c.zip < " + (City.ZIP_START + 10));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+
+ IntStream.range(0, 10).forEach(i -> replicateCities.put(i, new City(i)));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(10);
+ }
+
+ @Test
+ public void removeIndexWhileClear() throws Exception {
+ // create cityZip index
+ server1.invoke("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // remove index while clear
+ // removeIndex has to be invoked on each server. It's not distributed
+ AsyncInvocation removeIndex1 = server1.invokeAsync("remove index",
+ PRClearQueryIndexDUnitTest::removeCityZipIndex);
+ AsyncInvocation removeIndex2 = server2.invokeAsync("remove index",
+ PRClearQueryIndexDUnitTest::removeCityZipIndex);
+
+ cities.clear();
+ removeIndex1.await();
+ removeIndex2.await();
+
+ // make sure removeIndex and clear operations are successful
+ invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(0);
+ // verify only 2 indexes created in the beginning of the tests exist
+ assertThat(qs.getIndexes(region)).extracting(Index::getName)
+ .containsExactlyInAnyOrder("cityId", "cityName");
+ }, server1, server2);
+ }
+
+ private static void removeCityZipIndex() {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService qs = cache.getQueryService();
+ Region<Object, Object> region = cache.getRegion("cities");
+ Index cityZip = qs.getIndex(region, "cityZip");
+ if (cityZip != null) {
+ qs.removeIndex(cityZip);
+ }
+ }
+
+ @Test
+ public void verifyQuerySucceedsAfterClear() throws Exception {
+ // put in some data
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(50);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(1);
+
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
+ }
+
+ private static void verifyIndexesAfterClear(String regionName, String... indexes) {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion(regionName);
+ assertThat(region.size()).isEqualTo(0);
+ for (String indexName : indexes) {
+ Index index = qs.getIndex(region, indexName);
+ IndexStatistics statistics = index.getStatistics();
+ assertThat(statistics.getNumberOfKeys()).isEqualTo(0);
+ assertThat(statistics.getNumberOfValues()).isEqualTo(0);
+ }
+ }
+
+ @Test
+ public void concurrentClearAndQuery() {
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ server1.invokeAsync(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ region.clear();
+ });
+
+ await().untilAsserted(() -> {
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
+ });
+ }
+
+ @Test
+ public void concurrentClearAndPut() throws Exception {
+ AsyncInvocation puts = server1.invokeAsync(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ for (int i = 0; i < 1000; i++) {
+ // wait for gate to open
+ getBlackboard().waitForGate("proceedToPut", 60, TimeUnit.SECONDS);
+ region.put(i, new City(i));
+ }
+ });
+
+ AsyncInvocation clears = server2.invokeAsync(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // do clear 10 times
+ for (int i = 0; i < 10; i++) {
+ try {
+ // don't allow put to proceed. It's like "close the gate"
+ getBlackboard().clearGate("proceedToPut");
+ region.clear();
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ } finally {
+ // allow put to proceed. It's like "open the gate"
+ getBlackboard().signalGate("proceedToPut");
+ }
+ }
+ });
+
+ puts.await();
+ clears.await();
+ }
+
+ @Test
+ public void serverLeavingAndJoiningWhilePutAndClear() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ Future<Void> startStopServer = executor.submit(() -> {
+ for (int i = 0; i < 3; i++) {
+ MemberVM server3 = cluster.startServerVM(3, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server3.stop(false);
+ }
+ });
+
+ Future<Void> putAndClear = executor.submit(() -> {
+ for (int i = 0; i < 30; i++) {
+ IntStream.range(0, 100).forEach(j -> cities.put(j, new City(j)));
+ try {
+ cities.clear();
+ } catch (ServerOperationException e) {
+ assertThat(e.getCause().getMessage())
+ .contains("Unable to clear all the buckets from the partitioned region cities")
+ .contains("either data (buckets) moved or member departed");
+ }
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
Review comment:
The asserts here should probably be await.until's. Judging from the DUnit failure.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] jchen21 commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
jchen21 commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r476893010
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(2, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ private ClientCache clientCache;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(0, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ }
+
+ @Test
+ public void verifyQuerySucceedsAfterClear() throws Exception {
+ Region cities = clientCacheRule.createProxyRegion("cities");
+ // put in some data
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(100);
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(50);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(1);
+
+ cities.clear();
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(0);
+ }, server1, server2);
+
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
+
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion("cities");
+ Index cityId = qs.getIndex(region, "cityId");
+ IndexStatistics statistics = cityId.getStatistics();
+ assertThat(statistics.getNumberOfKeys()).isEqualTo(0);
+ assertThat(statistics.getNumberOfValues()).isEqualTo(0);
+ Index cityName = qs.getIndex(region, "cityName");
+ IndexStatistics statistics1 = cityName.getStatistics();
+ assertThat(statistics1.getNumberOfKeys()).isEqualTo(0);
+ assertThat(statistics1.getNumberOfValues()).isEqualTo(0);
+ }, server1, server2);
+ }
+
+ @Test
+ public void concurrentClearAndQuery() {
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+
+ server1.invokeAsync(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ IntStream.range(0, 100).forEach(i -> region.put(i, new City(i)));
+ region.clear();
+ });
+
+ await().pollDelay(5, TimeUnit.MILLISECONDS).untilAsserted(() -> {
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
Review comment:
I am not sure I understand the purpose of this test. Depends on the thread scheduling, the query result size could be non-zero. e.g. if the query is executed after populating the region, but before clearing the region.
The test result is non-deterministic. This test is flaky.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
mhansonp commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r481498183
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,374 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.junit.rules.VMProvider.invokeInEveryMember;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ServerOperationException;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.DUnitBlackboard;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(4, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ private static DUnitBlackboard blackboard;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ @Rule
+ public ExecutorServiceRule executor = ExecutorServiceRule.builder().build();
+
+ private ClientCache clientCache;
+ private Region cities;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(2, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ cities = clientCacheRule.createProxyRegion("cities");
+ }
+
+ @Test
+ public void clearOnEmptyRegion() throws Exception {
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+ }
+
+ @Test
+ public void createIndexWhileClear() throws Exception {
+ IntStream.range(0, 1000).forEach(i -> cities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear for 3 times at the same time to increease the concurrency of clear and createIndex
+ for (int i = 0; i < 3; i++) {
+ cities.clear();
+ }
+ createIndex.await();
+
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query =
+ queryService.newQuery("select * from /cities c where c.zip < " + (City.ZIP_START + 10));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(10);
+ }
+
+ @Test
+ public void createIndexWhileClearOnReplicateRegion() throws Exception {
+ invokeInEveryMember(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ cache.createRegionFactory(RegionShortcut.PARTITION)
+ .create("replicateCities");
+ }, server1, server2);
+
+ Region replicateCities = clientCacheRule.createProxyRegion("replicateCities");
+ IntStream.range(0, 1000).forEach(i -> replicateCities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index on replicate regions", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip_replicate", "c.zip", "/replicateCities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear at the same time for 3 timese
+ for (int i = 0; i < 3; i++) {
+ replicateCities.clear();
+ }
+ createIndex.await();
+
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("replicateCities", "cityZip_replicate");
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query =
+ queryService
+ .newQuery("select * from /replicateCities c where c.zip < " + (City.ZIP_START + 10));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+
+ IntStream.range(0, 10).forEach(i -> replicateCities.put(i, new City(i)));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(10);
+ }
+
+ @Test
+ public void removeIndexWhileClear() throws Exception {
+ // create cityZip index
+ server1.invoke("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // remove index while clear
+ // removeIndex has to be invoked on each server. It's not distributed
+ AsyncInvocation removeIndex1 = server1.invokeAsync("remove index",
+ PRClearQueryIndexDUnitTest::removeCityZipIndex);
+ AsyncInvocation removeIndex2 = server2.invokeAsync("remove index",
+ PRClearQueryIndexDUnitTest::removeCityZipIndex);
+
+ cities.clear();
+ removeIndex1.await();
+ removeIndex2.await();
+
+ // make sure removeIndex and clear operations are successful
+ invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(0);
+ // verify only 2 indexes created in the beginning of the tests exist
+ assertThat(qs.getIndexes(region)).extracting(Index::getName)
+ .containsExactlyInAnyOrder("cityId", "cityName");
+ }, server1, server2);
+ }
+
+ private static void removeCityZipIndex() {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService qs = cache.getQueryService();
+ Region<Object, Object> region = cache.getRegion("cities");
+ Index cityZip = qs.getIndex(region, "cityZip");
+ if (cityZip != null) {
+ qs.removeIndex(cityZip);
+ }
+ }
+
+ @Test
+ public void verifyQuerySucceedsAfterClear() throws Exception {
+ // put in some data
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(50);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(1);
+
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
+ }
+
+ private static void verifyIndexesAfterClear(String regionName, String... indexes) {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion(regionName);
+ assertThat(region.size()).isEqualTo(0);
+ for (String indexName : indexes) {
+ Index index = qs.getIndex(region, indexName);
+ IndexStatistics statistics = index.getStatistics();
+ assertThat(statistics.getNumberOfKeys()).isEqualTo(0);
+ assertThat(statistics.getNumberOfValues()).isEqualTo(0);
+ }
+ }
+
+ @Test
+ public void concurrentClearAndQuery() {
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ server1.invokeAsync(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ region.clear();
+ });
+
+ await().untilAsserted(() -> {
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
+ });
+ }
+
+ @Test
+ public void concurrentClearAndPut() throws Exception {
+ AsyncInvocation puts = server1.invokeAsync(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ for (int i = 0; i < 1000; i++) {
+ // wait for gate to open
+ getBlackboard().waitForGate("proceedToPut", 60, TimeUnit.SECONDS);
+ region.put(i, new City(i));
+ }
+ });
+
+ AsyncInvocation clears = server2.invokeAsync(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // do clear 10 times
+ for (int i = 0; i < 10; i++) {
+ try {
+ // don't allow put to proceed. It's like "close the gate"
+ getBlackboard().clearGate("proceedToPut");
+ region.clear();
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ } finally {
+ // allow put to proceed. It's like "open the gate"
+ getBlackboard().signalGate("proceedToPut");
+ }
+ }
+ });
+
+ puts.await();
+ clears.await();
+ }
+
+ @Test
+ public void serverLeavingAndJoiningWhilePutAndClear() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ Future<Void> startStopServer = executor.submit(() -> {
+ for (int i = 0; i < 3; i++) {
+ MemberVM server3 = cluster.startServerVM(3, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server3.stop(false);
+ }
+ });
+
+ Future<Void> putAndClear = executor.submit(() -> {
+ for (int i = 0; i < 30; i++) {
+ IntStream.range(0, 100).forEach(j -> cities.put(j, new City(j)));
+ try {
+ cities.clear();
+ } catch (ServerOperationException e) {
+ assertThat(e.getCause().getMessage())
+ .contains("Unable to clear all the buckets from the partitioned region cities")
+ .contains("either data (buckets) moved or member departed");
+ }
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
Review comment:
The asserts here should probably be await.untilAsserted's. Judging from the DUnit failure.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] jinmeiliao merged pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
jinmeiliao merged pull request #5436:
URL: https://github.com/apache/geode/pull/5436
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] agingade commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
agingade commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r478637836
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,369 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.junit.rules.VMProvider.invokeInEveryMember;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ServerOperationException;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.DUnitBlackboard;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(4, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ private static DUnitBlackboard blackboard;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ @Rule
+ public ExecutorServiceRule executor = ExecutorServiceRule.builder().build();
+
+ private ClientCache clientCache;
+ private Region cities;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(2, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
Review comment:
Another most commonly used index is range index; which gets created when multiple iterators are used in index expression, can you please add that one into the test.
qs.createIndex("sIndex", "pos.secId",
"portfolio.values val, val.positions.values pos");
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,369 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.junit.rules.VMProvider.invokeInEveryMember;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ServerOperationException;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.DUnitBlackboard;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(4, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ private static DUnitBlackboard blackboard;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ @Rule
+ public ExecutorServiceRule executor = ExecutorServiceRule.builder().build();
+
+ private ClientCache clientCache;
+ private Region cities;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(2, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ cities = clientCacheRule.createProxyRegion("cities");
+ }
+
+ @Test
+ public void clearOnEmptyRegion() throws Exception {
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear();
+ }, server1, server2);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear();
+ }, server1, server2);
+ }
+
+ @Test
+ public void createIndexWhileClear() throws Exception {
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear at the same time
+ cities.clear();
Review comment:
If the idea is to get clear and index to be happening parallel, this may not guarantee that. There is a IndexManager.testHook that can be used to control index creation. And having more entries will help chances of occurring clear and create-index in parallel.
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,369 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.junit.rules.VMProvider.invokeInEveryMember;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ServerOperationException;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.DUnitBlackboard;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(4, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ private static DUnitBlackboard blackboard;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ @Rule
+ public ExecutorServiceRule executor = ExecutorServiceRule.builder().build();
+
+ private ClientCache clientCache;
+ private Region cities;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(2, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ cities = clientCacheRule.createProxyRegion("cities");
+ }
+
+ @Test
+ public void clearOnEmptyRegion() throws Exception {
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear();
+ }, server1, server2);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear();
+ }, server1, server2);
+ }
+
+ @Test
+ public void createIndexWhileClear() throws Exception {
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear at the same time
+ cities.clear();
+ createIndex.await();
+
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear();
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query =
+ queryService.newQuery("select * from /cities c where c.zip < " + (City.ZIP_START + 10));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(10);
+ }
+
+ @Test
+ public void createIndexWhileClearOnReplicateRegion() throws Exception {
+ invokeInEveryMember(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ cache.createRegionFactory(RegionShortcut.PARTITION)
+ .create("replicateCities");
+ }, server1, server2);
+
+ Region replicateCities = clientCacheRule.createProxyRegion("replicateCities");
+ IntStream.range(0, 100).forEach(i -> replicateCities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index on replicate regions", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip_replicate", "c.zip", "/replicateCities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear at the same time
+ replicateCities.clear();
+ createIndex.await();
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query =
+ queryService
+ .newQuery("select * from /replicateCities c where c.zip < " + (City.ZIP_START + 10));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
Review comment:
This is a way to see how many entries are there in index. With this we need to make sure the query has used index.
Along with that it will be nice to validate the index storage size: it could be done by calling isEmpty() on Index class or using the index stats (as done in other places in this test)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] jinmeiliao commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
jinmeiliao commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r469576129
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(2, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ private ClientCache clientCache;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(0, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ }
+
+ @Test
+ public void verifyQuerySucceedsAfterClear() throws Exception {
+ Region cities = clientCacheRule.createProxyRegion("cities");
+ // put in some data
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
Review comment:
Yes, the PR is also to make sure this change won't break other tests. It's better not to make a different class if we can just add an id field and also not breaking others.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] jinmeiliao commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
jinmeiliao commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r485085252
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,374 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.junit.rules.VMProvider.invokeInEveryMember;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ServerOperationException;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.DUnitBlackboard;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(4, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ private static DUnitBlackboard blackboard;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ @Rule
+ public ExecutorServiceRule executor = ExecutorServiceRule.builder().build();
+
+ private ClientCache clientCache;
+ private Region cities;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(2, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ cities = clientCacheRule.createProxyRegion("cities");
+ }
+
+ @Test
+ public void clearOnEmptyRegion() throws Exception {
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+ }
+
+ @Test
+ public void createIndexWhileClear() throws Exception {
+ IntStream.range(0, 1000).forEach(i -> cities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear for 3 times at the same time to increease the concurrency of clear and createIndex
+ for (int i = 0; i < 3; i++) {
+ cities.clear();
+ }
+ createIndex.await();
+
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query =
+ queryService.newQuery("select * from /cities c where c.zip < " + (City.ZIP_START + 10));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(10);
+ }
+
+ @Test
+ public void createIndexWhileClearOnReplicateRegion() throws Exception {
+ invokeInEveryMember(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ cache.createRegionFactory(RegionShortcut.PARTITION)
+ .create("replicateCities");
+ }, server1, server2);
+
+ Region replicateCities = clientCacheRule.createProxyRegion("replicateCities");
+ IntStream.range(0, 1000).forEach(i -> replicateCities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index on replicate regions", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip_replicate", "c.zip", "/replicateCities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear at the same time for 3 timese
+ for (int i = 0; i < 3; i++) {
+ replicateCities.clear();
+ }
+ createIndex.await();
+
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("replicateCities", "cityZip_replicate");
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query =
+ queryService
+ .newQuery("select * from /replicateCities c where c.zip < " + (City.ZIP_START + 10));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+
+ IntStream.range(0, 10).forEach(i -> replicateCities.put(i, new City(i)));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(10);
+ }
+
+ @Test
+ public void removeIndexWhileClear() throws Exception {
+ // create cityZip index
+ server1.invoke("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // remove index while clear
+ // removeIndex has to be invoked on each server. It's not distributed
+ AsyncInvocation removeIndex1 = server1.invokeAsync("remove index",
+ PRClearQueryIndexDUnitTest::removeCityZipIndex);
+ AsyncInvocation removeIndex2 = server2.invokeAsync("remove index",
+ PRClearQueryIndexDUnitTest::removeCityZipIndex);
+
+ cities.clear();
+ removeIndex1.await();
+ removeIndex2.await();
+
+ // make sure removeIndex and clear operations are successful
+ invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(0);
+ // verify only 2 indexes created in the beginning of the tests exist
+ assertThat(qs.getIndexes(region)).extracting(Index::getName)
+ .containsExactlyInAnyOrder("cityId", "cityName");
+ }, server1, server2);
+ }
+
+ private static void removeCityZipIndex() {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService qs = cache.getQueryService();
+ Region<Object, Object> region = cache.getRegion("cities");
+ Index cityZip = qs.getIndex(region, "cityZip");
+ if (cityZip != null) {
+ qs.removeIndex(cityZip);
+ }
+ }
+
+ @Test
+ public void verifyQuerySucceedsAfterClear() throws Exception {
+ // put in some data
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(50);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(1);
+
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
+ }
+
+ private static void verifyIndexesAfterClear(String regionName, String... indexes) {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion(regionName);
+ assertThat(region.size()).isEqualTo(0);
+ for (String indexName : indexes) {
+ Index index = qs.getIndex(region, indexName);
+ IndexStatistics statistics = index.getStatistics();
+ assertThat(statistics.getNumberOfKeys()).isEqualTo(0);
Review comment:
this method is called AFTER clear is done, so it should be 0 at this point all the time.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] mhansonp commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
mhansonp commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r481498899
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,374 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.apache.geode.test.junit.rules.VMProvider.invokeInEveryMember;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ServerOperationException;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.DUnitBlackboard;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(4, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ private static DUnitBlackboard blackboard;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ @Rule
+ public ExecutorServiceRule executor = ExecutorServiceRule.builder().build();
+
+ private ClientCache clientCache;
+ private Region cities;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(2, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region))
+ .extracting(Index::getName).containsExactlyInAnyOrder("cityId", "cityName");
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ cities = clientCacheRule.createProxyRegion("cities");
+ }
+
+ @Test
+ public void clearOnEmptyRegion() throws Exception {
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+ }
+
+ @Test
+ public void createIndexWhileClear() throws Exception {
+ IntStream.range(0, 1000).forEach(i -> cities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear for 3 times at the same time to increease the concurrency of clear and createIndex
+ for (int i = 0; i < 3; i++) {
+ cities.clear();
+ }
+ createIndex.await();
+
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query =
+ queryService.newQuery("select * from /cities c where c.zip < " + (City.ZIP_START + 10));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+
+ IntStream.range(0, 10).forEach(i -> cities.put(i, new City(i)));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(10);
+ }
+
+ @Test
+ public void createIndexWhileClearOnReplicateRegion() throws Exception {
+ invokeInEveryMember(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ cache.createRegionFactory(RegionShortcut.PARTITION)
+ .create("replicateCities");
+ }, server1, server2);
+
+ Region replicateCities = clientCacheRule.createProxyRegion("replicateCities");
+ IntStream.range(0, 1000).forEach(i -> replicateCities.put(i, new City(i)));
+
+ // create index while clear
+ AsyncInvocation createIndex = server1.invokeAsync("create index on replicate regions", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip_replicate", "c.zip", "/replicateCities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // do clear at the same time for 3 timese
+ for (int i = 0; i < 3; i++) {
+ replicateCities.clear();
+ }
+ createIndex.await();
+
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("replicateCities", "cityZip_replicate");
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query =
+ queryService
+ .newQuery("select * from /replicateCities c where c.zip < " + (City.ZIP_START + 10));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+
+ IntStream.range(0, 10).forEach(i -> replicateCities.put(i, new City(i)));
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(10);
+ }
+
+ @Test
+ public void removeIndexWhileClear() throws Exception {
+ // create cityZip index
+ server1.invoke("create index", () -> {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService queryService = cache.getQueryService();
+ Index cityZip = queryService.createIndex("cityZip", "c.zip", "/cities c");
+ assertThat(cityZip).isNotNull();
+ });
+
+ // remove index while clear
+ // removeIndex has to be invoked on each server. It's not distributed
+ AsyncInvocation removeIndex1 = server1.invokeAsync("remove index",
+ PRClearQueryIndexDUnitTest::removeCityZipIndex);
+ AsyncInvocation removeIndex2 = server2.invokeAsync("remove index",
+ PRClearQueryIndexDUnitTest::removeCityZipIndex);
+
+ cities.clear();
+ removeIndex1.await();
+ removeIndex2.await();
+
+ // make sure removeIndex and clear operations are successful
+ invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(0);
+ // verify only 2 indexes created in the beginning of the tests exist
+ assertThat(qs.getIndexes(region)).extracting(Index::getName)
+ .containsExactlyInAnyOrder("cityId", "cityName");
+ }, server1, server2);
+ }
+
+ private static void removeCityZipIndex() {
+ Cache cache = ClusterStartupRule.getCache();
+ QueryService qs = cache.getQueryService();
+ Region<Object, Object> region = cache.getRegion("cities");
+ Index cityZip = qs.getIndex(region, "cityZip");
+ if (cityZip != null) {
+ qs.removeIndex(cityZip);
+ }
+ }
+
+ @Test
+ public void verifyQuerySucceedsAfterClear() throws Exception {
+ // put in some data
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(50);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(1);
+
+ cities.clear();
+ invokeInEveryMember(() -> {
+ verifyIndexesAfterClear("cities", "cityId", "cityName");
+ }, server1, server2);
+
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
+ }
+
+ private static void verifyIndexesAfterClear(String regionName, String... indexes) {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion(regionName);
+ assertThat(region.size()).isEqualTo(0);
+ for (String indexName : indexes) {
+ Index index = qs.getIndex(region, indexName);
+ IndexStatistics statistics = index.getStatistics();
+ assertThat(statistics.getNumberOfKeys()).isEqualTo(0);
Review comment:
Would this be better as an await.untilAsserted?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] jinmeiliao commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
jinmeiliao commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r477410555
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(2, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ private ClientCache clientCache;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(0, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ }
+
+ @Test
+ public void verifyQuerySucceedsAfterClear() throws Exception {
+ Region cities = clientCacheRule.createProxyRegion("cities");
+ // put in some data
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(100);
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(50);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(1);
+
+ cities.clear();
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(0);
+ }, server1, server2);
+
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
+
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion("cities");
+ Index cityId = qs.getIndex(region, "cityId");
+ IndexStatistics statistics = cityId.getStatistics();
+ assertThat(statistics.getNumberOfKeys()).isEqualTo(0);
+ assertThat(statistics.getNumberOfValues()).isEqualTo(0);
+ Index cityName = qs.getIndex(region, "cityName");
+ IndexStatistics statistics1 = cityName.getStatistics();
+ assertThat(statistics1.getNumberOfKeys()).isEqualTo(0);
+ assertThat(statistics1.getNumberOfValues()).isEqualTo(0);
+ }, server1, server2);
+ }
+
+ @Test
+ public void concurrentClearAndQuery() {
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+
+ server1.invokeAsync(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ IntStream.range(0, 100).forEach(i -> region.put(i, new City(i)));
+ region.clear();
+ });
+
+ await().pollDelay(5, TimeUnit.MILLISECONDS).untilAsserted(() -> {
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
Review comment:
the `await().untilAsserted()` method will keep on executing the code block inside until it's successful or until it timed out. This test is trying to execute `clear()` and `query()` at the same time, and make sure that query will eventually return 0 results with no errors.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [geode] jchen21 commented on a change in pull request #5436: GEODE-7672: add dunit test to verify OQL index after PR clear.
Posted by GitBox <gi...@apache.org>.
jchen21 commented on a change in pull request #5436:
URL: https://github.com/apache/geode/pull/5436#discussion_r468778063
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(2, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ private ClientCache clientCache;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(0, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ }
+
+ @Test
+ public void verifyQuerySucceedsAfterClear() throws Exception {
+ Region cities = clientCacheRule.createProxyRegion("cities");
+ // put in some data
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
+
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(100);
+ }, server1, server2);
+
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(50);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(1);
+
+ cities.clear();
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ Region region = internalCache.getRegion("cities");
+ assertThat(region.size()).isEqualTo(0);
+ }, server1, server2);
+
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
+ assertThat(((SelectResults) query2.execute()).size()).isEqualTo(0);
+
+ MemberVM.invokeInEveryMember(() -> {
+ InternalCache internalCache = ClusterStartupRule.getCache();
+ QueryService qs = internalCache.getQueryService();
+ Region region = internalCache.getRegion("cities");
+ Index cityId = qs.getIndex(region, "cityId");
+ IndexStatistics statistics = cityId.getStatistics();
+ assertThat(statistics.getNumberOfKeys()).isEqualTo(0);
+ assertThat(statistics.getNumberOfValues()).isEqualTo(0);
+ Index cityName = qs.getIndex(region, "cityName");
+ IndexStatistics statistics1 = cityName.getStatistics();
+ assertThat(statistics1.getNumberOfKeys()).isEqualTo(0);
+ assertThat(statistics1.getNumberOfValues()).isEqualTo(0);
+ }, server1, server2);
+ }
+
+ @Test
+ public void concurrentClearAndQuery() {
+ QueryService queryService = clientCache.getQueryService();
+ Query query = queryService.newQuery(MUMBAI_QUERY);
+ Query query2 = queryService.newQuery(ID_10_QUERY);
+
+ server1.invokeAsync(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ IntStream.range(0, 100).forEach(i -> region.put(i, new City(i)));
+ region.clear();
+ });
+
+ await().pollDelay(5, TimeUnit.MILLISECONDS).untilAsserted(() -> {
+ assertThat(((SelectResults) query.execute()).size()).isEqualTo(0);
Review comment:
The assertions here could be executed before `region.clear()` in line 148, or even before the region is populated. There is no guarantee when the code block in `invokeAsync` is executed.
##########
File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/partitioned/PRClearQueryIndexDUnitTest.java
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.query.partitioned;
+
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexStatistics;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.City;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.rules.ClientCacheRule;
+
+public class PRClearQueryIndexDUnitTest {
+ public static final String MUMBAI_QUERY = "select * from /cities c where c.name = 'MUMBAI'";
+ public static final String ID_10_QUERY = "select * from /cities c where c.id = 10";
+ @ClassRule
+ public static ClusterStartupRule cluster = new ClusterStartupRule(2, true);
+
+ private static MemberVM server1;
+ private static MemberVM server2;
+
+ @Rule
+ public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+ private ClientCache clientCache;
+
+ // class test setup. set up the servers, regions and indexes on the servers
+ @BeforeClass
+ public static void beforeClass() {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ server1 = cluster.startServerVM(0, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+ server2 = cluster.startServerVM(1, s -> s.withConnectionToLocator(locatorPort)
+ .withProperty(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.cache.query.data.*")
+ .withRegion(RegionShortcut.PARTITION, "cities"));
+
+ server1.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ // create indexes
+ QueryService queryService = cache.getQueryService();
+ queryService.createKeyIndex("cityId", "c.id", "/cities c");
+ queryService.createIndex("cityName", "c.name", "/cities c");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+
+ server2.invoke(() -> {
+ Cache cache = ClusterStartupRule.getCache();
+ Region region = cache.getRegion("cities");
+ assertThat(cache.getQueryService().getIndexes(region)).hasSize(2);
+ });
+ }
+
+ // before every test method, create the client cache and region
+ @Before
+ public void before() throws Exception {
+ int locatorPort = ClusterStartupRule.getDUnitLocatorPort();
+ clientCache = clientCacheRule.withLocatorConnection(locatorPort).createCache();
+ }
+
+ @Test
+ public void verifyQuerySucceedsAfterClear() throws Exception {
+ Region cities = clientCacheRule.createProxyRegion("cities");
+ // put in some data
+ IntStream.range(0, 100).forEach(i -> cities.put(i, new City(i)));
Review comment:
The `City` class is defined in another package used by other tests. Any changes in `City` could potentially break the test. I would recommend using a class defined within the test itself. It is easier to maintain the code.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org