gesterzhou commented on a change in pull request #6561: URL: https://github.com/apache/geode/pull/6561#discussion_r652329938
########## File path: geode-core/src/distributedTest/java/org/apache/geode/cache/query/dunit/PdxMultiThreadQueryDUnitTest.java ########## @@ -0,0 +1,271 @@ +/* + * 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.dunit; + +import static org.apache.geode.test.awaitility.GeodeAwaitility.await; +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.logging.log4j.Logger; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import org.apache.geode.cache.CacheException; +import org.apache.geode.cache.Region; +import org.apache.geode.cache.client.ClientCache; +import org.apache.geode.cache.client.ClientCacheFactory; +import org.apache.geode.cache.client.ClientRegionShortcut; +import org.apache.geode.cache.client.PoolManager; +import org.apache.geode.cache.query.FunctionDomainException; +import org.apache.geode.cache.query.NameResolutionException; +import org.apache.geode.cache.query.Query; +import org.apache.geode.cache.query.QueryInvocationTargetException; +import org.apache.geode.cache.query.QueryService; +import org.apache.geode.cache.query.SelectResults; +import org.apache.geode.cache.query.TypeMismatchException; +import org.apache.geode.logging.internal.log4j.api.LogService; +import org.apache.geode.pdx.PdxReader; +import org.apache.geode.pdx.PdxSerializable; +import org.apache.geode.pdx.PdxSerializationException; +import org.apache.geode.pdx.PdxWriter; +import org.apache.geode.test.dunit.AsyncInvocation; +import org.apache.geode.test.dunit.Host; +import org.apache.geode.test.dunit.NetworkUtils; +import org.apache.geode.test.dunit.VM; +import org.apache.geode.test.junit.categories.OQLQueryTest; +import org.apache.geode.test.version.VersionManager; + +@Category({OQLQueryTest.class}) +public class PdxMultiThreadQueryDUnitTest extends PDXQueryTestBase { + public static final Logger logger = LogService.getLogger(); + + static final int numberOfEntries = 100; + + public PdxMultiThreadQueryDUnitTest() { + super(); + } + + @Test + public void testClientServerQuery() throws CacheException { + final Host host = Host.getHost(0); + final String hostName = NetworkUtils.getServerHostName(); + + VM vm0 = host.getVM(VersionManager.CURRENT_VERSION, 0); + VM vm1 = host.getVM(VersionManager.CURRENT_VERSION, 1); + VM vm2 = host.getVM(VersionManager.CURRENT_VERSION, 2); + VM vm3 = host.getVM(VersionManager.CURRENT_VERSION, 3); + + // Start servers + for (VM vm : Arrays.asList(vm0, vm1, vm2)) { + vm.invoke(() -> { + configAndStartBridgeServer(); + }); + } + + // create pdx instance at servers + vm0.invoke(() -> { + Region region = getRootRegion().getSubregion(regionName); + for (int i = 0; i < numberOfEntries; i++) { + region.put("key-" + i, new TestObject(i, "vmware")); + } + }); + + final int port0 = vm0.invoke(() -> PdxQueryDUnitTest.getCacheServerPort()); + final int port1 = vm1.invoke(() -> PdxQueryDUnitTest.getCacheServerPort()); + final int port2 = vm2.invoke(() -> PdxQueryDUnitTest.getCacheServerPort()); + + // Create client region + vm3.invoke(() -> { + ClientCacheFactory cf = new ClientCacheFactory(); + cf.addPoolServer(hostName, port1); + cf.addPoolServer(hostName, port2); + cf.addPoolServer(hostName, port0); + cf.setPdxReadSerialized(false); + ClientCache clientCache = getClientCache(cf); + Region region = + clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regionName); + + logger.info("### Executing Query on server: " + queryString[1] + ": from client region: " + + region.getFullPath()); + final int size = 100; + int[] array = new int[size]; + for (int i = 0; i < size; i++) { + array[i] = i; + } + Arrays.stream(array).parallel().forEach(a -> { Review comment: that code was copied from customer's test 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: [email protected]
