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 2022/05/09 15:39:50 UTC

[GitHub] [geode] pivotal-jbarrett commented on a diff in pull request #7652: GEODE-10271: ConnectionProxyJUnitTest cleanup

pivotal-jbarrett commented on code in PR #7652:
URL: https://github.com/apache/geode/pull/7652#discussion_r868152259


##########
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/tier/sockets/ConnectionProxyJUnitTest.java:
##########
@@ -19,753 +19,377 @@
 package org.apache.geode.internal.cache.tier.sockets;
 
 import static org.apache.geode.cache.client.PoolManager.createFactory;
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
 import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.fail;
 
+import java.io.IOException;
 import java.time.Duration;
 import java.util.Map;
-import java.util.Properties;
 
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import org.apache.geode.cache.AttributesFactory;
 import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.EntryEvent;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
+import org.apache.geode.cache.client.NoAvailableServersException;
 import org.apache.geode.cache.client.PoolFactory;
 import org.apache.geode.cache.client.PoolManager;
-import org.apache.geode.cache.client.internal.Connection;
 import org.apache.geode.cache.client.internal.PoolImpl;
-import org.apache.geode.cache.client.internal.PutOp;
 import org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject;
 import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.cache.util.CacheListenerAdapter;
 import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.internal.cache.EntryEventImpl;
 import org.apache.geode.internal.cache.EventID;
 import org.apache.geode.internal.cache.ha.ThreadIdentifier;
-import org.apache.geode.test.awaitility.GeodeAwaitility;
 import org.apache.geode.test.junit.categories.ClientSubscriptionTest;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
 
 /**
- *
  * Tests the functionality of operations of AbstractConnectionProxy & its derived classes.
  */
 @Category({ClientSubscriptionTest.class})
 public class ConnectionProxyJUnitTest {

Review Comment:
   Rename this test to the current naming convention.



##########
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/tier/sockets/ConnectionProxyJUnitTest.java:
##########
@@ -19,753 +19,377 @@
 package org.apache.geode.internal.cache.tier.sockets;
 
 import static org.apache.geode.cache.client.PoolManager.createFactory;
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
 import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.fail;
 
+import java.io.IOException;
 import java.time.Duration;
 import java.util.Map;
-import java.util.Properties;
 
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import org.apache.geode.cache.AttributesFactory;
 import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.EntryEvent;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
+import org.apache.geode.cache.client.NoAvailableServersException;
 import org.apache.geode.cache.client.PoolFactory;
 import org.apache.geode.cache.client.PoolManager;
-import org.apache.geode.cache.client.internal.Connection;
 import org.apache.geode.cache.client.internal.PoolImpl;
-import org.apache.geode.cache.client.internal.PutOp;
 import org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject;
 import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.cache.util.CacheListenerAdapter;
 import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.internal.cache.EntryEventImpl;
 import org.apache.geode.internal.cache.EventID;
 import org.apache.geode.internal.cache.ha.ThreadIdentifier;
-import org.apache.geode.test.awaitility.GeodeAwaitility;
 import org.apache.geode.test.junit.categories.ClientSubscriptionTest;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
 
 /**
- *
  * Tests the functionality of operations of AbstractConnectionProxy & its derived classes.
  */
 @Category({ClientSubscriptionTest.class})
 public class ConnectionProxyJUnitTest {
-  private static final String expectedRedundantErrorMsg =
-      "Could not find any server to host redundant client queue.";
-  private static final String expectedPrimaryErrorMsg =
-      "Could not find any server to host primary client queue.";
-
   DistributedSystem system;
-
   Cache cache;
-
   PoolImpl proxy = null;
-
   SequenceIdAndExpirationObject seo = null;
+  CacheServer server = null;
 
   final Duration timeoutToVerifyExpiry = Duration.ofSeconds(30);
   final Duration timeoutToVerifyAckSend = Duration.ofSeconds(30);
 
+  @Rule
+  public ServerStarterRule serverStarter =
+      new ServerStarterRule().withNoCacheServer().withAutoStart();
+
   @Before
   public void setUp() throws Exception {
-
-    Properties p = new Properties();
-    p.setProperty(MCAST_PORT, "0");
-    p.setProperty(LOCATORS, "");
-    system = DistributedSystem.connect(p);
-    cache = CacheFactory.create(system);
-    final String addExpectedPEM =
-        "<ExpectedException action=add>" + expectedPrimaryErrorMsg + "</ExpectedException>";
-    final String addExpectedREM =
-        "<ExpectedException action=add>" + expectedRedundantErrorMsg + "</ExpectedException>";
-    system.getLogWriter().info(addExpectedPEM);
-    system.getLogWriter().info(addExpectedREM);
+    cache = serverStarter.getCache();
+    system = cache.getDistributedSystem();
   }
 
   @After
-  public void tearDown() throws Exception {
-    cache.close();
-
-    final String removeExpectedPEM =
-        "<ExpectedException action=remove>" + expectedPrimaryErrorMsg + "</ExpectedException>";
-    final String removeExpectedREM =
-        "<ExpectedException action=remove>" + expectedRedundantErrorMsg + "</ExpectedException>";
-
-    system.getLogWriter().info(removeExpectedPEM);
-    system.getLogWriter().info(removeExpectedREM);
-
-    system.disconnect();
-    if (proxy != null) {
-      proxy.destroy();
+  public void after() throws Exception {
+    if (server != null) {
+      server.stop();
     }
   }
 
-  /**
-   * This test verifies the behaviour of client request when the listener on the server sits
-   * forever. This is done in following steps:<br>
-   * 1)create server<br>
-   * 2)initialize proxy object and create region for client having a CacheListener and make
-   * afterCreate in the listener to wait infinitely<br>
-   * 3)perform a PUT on client by acquiring Connection through proxy<br>
-   * 4)Verify that exception occurs due to infinite wait in the listener<br>
-   * 5)Verify that above exception occurs sometime after the readTimeout configured for the client
-   * <br>
-   *
-   */
-  @Ignore
   @Test
-  public void testListenerOnServerSitForever() throws Exception {
+  public void testConnectedServerCount() throws Exception {
     int port3 = getRandomAvailableTCPPort();
-    Region testRegion = null;
 
-    CacheServer server = cache.addCacheServer();
-    server.setMaximumTimeBetweenPings(10000);
-    server.setPort(port3);
-    server.start();
+    PoolFactory pf = PoolManager.createFactory();
+    pf.addServer("localhost", port3);

Review Comment:
   Even in tests let's use full meaningful symbol names.



-- 
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: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org