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/05/14 21:19:42 UTC

[GitHub] [geode] kirklund commented on a change in pull request #5111: GEODE-8078: log and report error at the correct place.

kirklund commented on a change in pull request #5111:
URL: https://github.com/apache/geode/pull/5111#discussion_r425429930



##########
File path: geode-web-management/src/distributedTest/java/org/apache/geode/management/client/GetStartingMemberTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.management.client;
+
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.context.WebApplicationContext;
+
+import org.apache.geode.management.api.ClusterManagementException;
+import org.apache.geode.management.api.ClusterManagementGetResult;
+import org.apache.geode.management.api.ClusterManagementService;
+import org.apache.geode.management.api.RestTemplateClusterManagementServiceTransport;
+import org.apache.geode.management.configuration.Member;
+import org.apache.geode.management.internal.rest.LocatorWebContext;
+import org.apache.geode.management.internal.rest.PlainLocatorContextLoader;
+import org.apache.geode.management.runtime.MemberInformation;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.junit.rules.ConcurrencyRule;
+
+@RunWith(SpringRunner.class)
+@ContextConfiguration(locations = {"classpath*:WEB-INF/management-servlet.xml"},
+    loader = PlainLocatorContextLoader.class)
+@WebAppConfiguration
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
+public class GetStartingMemberTest {
+
+  @Autowired
+  private WebApplicationContext webApplicationContext;
+
+  @Rule
+  public ClusterStartupRule cluster = new ClusterStartupRule(1);
+
+  @Rule
+  public ConcurrencyRule concurrency = new ConcurrencyRule();
+
+  private ClusterManagementService client;
+  private LocatorWebContext webContext;
+
+  @Before
+  public void before() {
+    cluster.setSkipLocalDistributedSystemCleanup(true);
+    webContext = new LocatorWebContext(webApplicationContext);
+    client = new ClusterManagementServiceBuilder().setTransport(
+        new RestTemplateClusterManagementServiceTransport(
+            new RestTemplate(webContext.getRequestFactory())))
+        .build();
+  }
+
+  @Test
+  public void getStartingMember() throws Exception {
+    Member server0 = new Member();
+    server0.setId("server-0");
+    concurrency.add(() -> cluster.startServerVM(0, webContext.getLocator().getPort()));
+    concurrency.add(() -> {
+      ClusterManagementGetResult<Member, MemberInformation> result = null;
+      while (result == null) {

Review comment:
       I recommend using GeodeAwaitility instead of a while-loop without timeout (I realize that ConcurrencyRule is ultimately providing the cancellation):
   ```
   await()
     .ignoreException(ClusterManagementException.class)
     .until(() -> client.get(server0) != null);
   ```
   

##########
File path: geode-core/src/main/java/org/apache/geode/management/internal/functions/CacheRealizationFunction.java
##########
@@ -78,24 +79,44 @@
   public void execute(FunctionContext<List> context) {
     AbstractConfiguration cacheElement = (AbstractConfiguration) context.getArguments().get(0);
     CacheElementOperation operation = (CacheElementOperation) context.getArguments().get(1);
-    RemoteInputStream jarStream = (RemoteInputStream) context.getArguments().get(2);
 
-    InternalCache cache = (InternalCache) context.getCache();
-    try {
-      if (operation == CacheElementOperation.GET) {
+    // for get operation, caller is expecting RuntimeInfo
+    if (operation == CacheElementOperation.GET) {
+      try {
+        InternalCache cache = (InternalCache) context.getCache();
         context.getResultSender().lastResult(executeGet(context, cache, cacheElement));
-      } else {
+      } catch (CacheClosedException e) {
+        // cache not ready or closed already, no need to log and do not return any runtime info
+        context.getResultSender().lastResult(null);
+      } catch (Exception e) {
+        logError("Unable to gather runtime information on this member. ", e);
+        context.getResultSender().lastResult(null);
+      }
+    }
+    // for other operations, caller is expecting RealizationResult
+    else {
+      try {
+        RemoteInputStream jarStream = (RemoteInputStream) context.getArguments().get(2);
+        InternalCache cache = (InternalCache) context.getCache();
         context.getResultSender()
             .lastResult(executeUpdate(context, cache, cacheElement, operation, jarStream));
+      } catch (CacheClosedException e) {
+        // cache not ready or closed already, no need to log it
+        context.getResultSender().lastResult(new RealizationResult()
+            .setSuccess(false)
+            .setMessage(e.getMessage()));
+      } catch (Exception e) {
+        logError("unable to update cache with the configuration.", e);
+        context.getResultSender().lastResult(new RealizationResult()
+            .setSuccess(false)
+            .setMemberName(context.getMemberName())
+            .setMessage(e.getMessage()));
       }
-    } catch (Exception e) {
-      logger.error(e.getMessage(), e);
-      context.getResultSender().lastResult(new RealizationResult()
-          .setSuccess(false)
-          .setMemberName(context.getMemberName())
-          .setMessage(e.getMessage()));
     }
+  }
 
+  void logError(String s, Exception e) {

Review comment:
       I recommend annotating with `@VisibleForTesting` because the method would probably be private if we didn't need to call it directly for testing.

##########
File path: geode-web-management/src/distributedTest/java/org/apache/geode/management/client/GetStartingMemberTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.management.client;
+
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.context.WebApplicationContext;
+
+import org.apache.geode.management.api.ClusterManagementException;
+import org.apache.geode.management.api.ClusterManagementGetResult;
+import org.apache.geode.management.api.ClusterManagementService;
+import org.apache.geode.management.api.RestTemplateClusterManagementServiceTransport;
+import org.apache.geode.management.configuration.Member;
+import org.apache.geode.management.internal.rest.LocatorWebContext;
+import org.apache.geode.management.internal.rest.PlainLocatorContextLoader;
+import org.apache.geode.management.runtime.MemberInformation;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.junit.rules.ConcurrencyRule;
+
+@RunWith(SpringRunner.class)
+@ContextConfiguration(locations = {"classpath*:WEB-INF/management-servlet.xml"},
+    loader = PlainLocatorContextLoader.class)
+@WebAppConfiguration
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
+public class GetStartingMemberTest {
+
+  @Autowired
+  private WebApplicationContext webApplicationContext;
+
+  @Rule
+  public ClusterStartupRule cluster = new ClusterStartupRule(1);
+
+  @Rule
+  public ConcurrencyRule concurrency = new ConcurrencyRule();
+
+  private ClusterManagementService client;
+  private LocatorWebContext webContext;
+
+  @Before
+  public void before() {
+    cluster.setSkipLocalDistributedSystemCleanup(true);
+    webContext = new LocatorWebContext(webApplicationContext);
+    client = new ClusterManagementServiceBuilder().setTransport(
+        new RestTemplateClusterManagementServiceTransport(
+            new RestTemplate(webContext.getRequestFactory())))
+        .build();
+  }
+
+  @Test
+  public void getStartingMember() throws Exception {
+    Member server0 = new Member();
+    server0.setId("server-0");
+    concurrency.add(() -> cluster.startServerVM(0, webContext.getLocator().getPort()));
+    concurrency.add(() -> {
+      ClusterManagementGetResult<Member, MemberInformation> result = null;
+      while (result == null) {
+        try {
+          result = client.get(server0);
+        } catch (ClusterManagementException e) {
+          // this is expected for the first several tries
+        }
+      }
+      return result;
+    });
+    concurrency.executeInParallel();

Review comment:
       ExecutorServiceRule would really clean this up and I think we should look into merging these two rules. In general, I think ExecutorServiceRule is preferable (I can explain outside of PR). If you switch to ExecutorServiceRule the test could use an assertion in await and seems much more readable to me:
   ```
   import static java.util.concurrent.TimeUnit.MILLISECONDS;
   import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
   import static org.assertj.core.api.Assertions.assertThat;
   
     @Rule
     public ExecutorServiceRule executorServiceRule = new ExecutorServiceRule();
   
     @Test
     public void getStartingMember() throws Exception {
       Member server0 = new Member();
       server0.setId("server-0");
   
       Future<Void> startServer = executorServiceRule.submit(() -> {
         cluster.startServerVM(0, webContext.getLocator().getPort());
       });
   
       await()
           .ignoreException(ClusterManagementException.class)
           .untilAsserted(() -> assertThat(client.get(server0)).isNotNull());
   
       startServer.get(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.

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