kirklund commented on a change in pull request #7014: URL: https://github.com/apache/geode/pull/7014#discussion_r732987267
########## File path: geode-core/src/distributedTest/java/org/apache/geode/security/DurableClientFailoverDUnitTest.java ########## @@ -0,0 +1,124 @@ +/* + * + * 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.security; + +import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID; +import static org.apache.geode.test.awaitility.GeodeAwaitility.await; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.concurrent.TimeUnit; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import org.apache.geode.cache.InterestResultPolicy; +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.ClientRegionShortcut; +import org.apache.geode.cache.client.PoolManager; +import org.apache.geode.cache.client.internal.PoolImpl; +import org.apache.geode.cache.client.internal.QueueConnectionImpl; +import org.apache.geode.cache.query.dunit.SecurityTestUtils.KeysCacheListener; +import org.apache.geode.test.concurrent.FileBasedCountDownLatch; +import org.apache.geode.test.dunit.AsyncInvocation; +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 DurableClientFailoverDUnitTest { + private MemberVM locator; + private MemberVM server1; + private MemberVM server2; + private MemberVM server3; + + @Rule + public ClusterStartupRule cluster = new ClusterStartupRule(); + + @Rule + public ClientCacheRule clientCacheRule = new ClientCacheRule(); + + @Before + public void setup() { + locator = cluster.startLocatorVM(0); + int locatorPort = locator.getPort(); + server1 = + cluster.startServerVM(1, s -> s.withRegion(RegionShortcut.REPLICATE_PERSISTENT, "region") + .withConnectionToLocator(locatorPort)); + server2 = + cluster.startServerVM(2, s -> s.withRegion(RegionShortcut.REPLICATE_PERSISTENT, "region") + .withConnectionToLocator(locatorPort)); + } + + @Test + public void durableClientGetAllEvents() throws Exception { + String clientId = "client0"; + clientCacheRule + .withCacheSetup(cf -> cf.setPoolSubscriptionEnabled(true).setPoolSubscriptionRedundancy(2)) + .withProperty(DURABLE_CLIENT_ID, clientId) + .withLocatorConnection(locator.getPort()); + ClientCache clientCache = clientCacheRule.createCache(); + + KeysCacheListener mylistener = new KeysCacheListener(); + Region<Object, Object> clientRegion = + clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY) + .addCacheListener(mylistener).create("region"); + clientRegion.registerInterestForAllKeys(InterestResultPolicy.NONE, true); + clientCache.readyForEvents(); + + // find out which server is the primary subscription end point, server1 or server2 + boolean server1IsPrimary = false; + PoolImpl pool = (PoolImpl) PoolManager.find(clientRegion.getAttributes().getPoolName()); + QueueConnectionImpl connection = (QueueConnectionImpl) pool.getPrimaryConnection(); + if (connection.toString().contains("server-1")) { + server1IsPrimary = true; + } + + // use server3 to input data constantly + int locatorPort = locator.getPort(); + server3 = + cluster.startServerVM(3, s -> s.withRegion(RegionShortcut.REPLICATE_PERSISTENT, "region") + .withConnectionToLocator(locatorPort)); + + FileBasedCountDownLatch latch = new FileBasedCountDownLatch(1); Review comment: The idea is to add a static atomic to the test class: ``` private static final AtomicReference<CountDownLatch> LATCH = new AtomicReference<>(new CountDownLatch(0)); ``` ``` @Before public void setUp() { vm.invoke(() -> LATCH.set(new CountDownLatch(1))); And then in the test, a `vm.invoke` or `vm.invokeAsync` uses that static from a remote VM: ``` AsyncInvocation<Void> hangInVM0 = getVM(0).invokeAsync(() -> { THREAD_ID.set(Thread.currentThread().getId()); LATCH.get().await(getTimeout().toMillis(), MILLISECONDS); }); ``` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
