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/01/07 23:14:04 UTC

[GitHub] [geode] mhansonp commented on a change in pull request #7217: GEODE-9758: Add internal serial filter API

mhansonp commented on a change in pull request #7217:
URL: https://github.com/apache/geode/pull/7217#discussion_r780462336



##########
File path: geode-assembly/src/acceptanceTest/java/org/apache/geode/serialization/filter/LocatorLauncherGlobalSerialFilterAcceptanceTest.java
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.serialization.filter;
+
+import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
+import static org.apache.commons.lang3.JavaVersion.JAVA_9;
+import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
+import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assumptions.assumeThat;
+
+import java.io.File;
+import java.nio.file.Path;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
+import org.apache.geode.rules.ServiceJarRule;
+import org.apache.geode.test.assertj.LogFileAssert;
+import org.apache.geode.test.junit.rules.gfsh.GfshRule;
+
+public class LocatorLauncherGlobalSerialFilterAcceptanceTest {
+
+  @Rule
+  public GfshRule gfshRule = new GfshRule();
+
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Rule
+  public ServiceJarRule serviceJarRule = new ServiceJarRule();
+
+  private File locatorFolder;
+
+  @Test
+  public void startLocatorDoesNotConfigureGlobalSerialFilter_onJava8() {
+    assumeThat(isJavaVersionAtMost(JAVA_1_8)).isTrue();
+
+    locatorFolder = temporaryFolder.getRoot();
+
+    int[] ports = getRandomAvailableTCPPorts(2);
+
+    int locatorPort = ports[0];
+    int locatorJmxPort = ports[1];
+
+    String startLocatorCommand = String.join(" ",
+        "start locator",
+        "--name=locator",
+        "--dir=" + locatorFolder.getAbsolutePath(),
+        "--port=" + locatorPort,
+        "--J=-Dgemfire.jmx-manager-port=" + locatorJmxPort);
+
+    gfshRule.execute(startLocatorCommand);
+
+    try {
+      Path locatorLogFile = locatorFolder.toPath().resolve("locator.log");
+      await().untilAsserted(() -> {
+        LogFileAssert.assertThat(locatorLogFile.toFile()).exists()
+            .doesNotContain("Global serial filter is now configured.")
+            .doesNotContain("jdk.serialFilter");
+      });
+    } finally {
+      String stopLocatorCommand = "stop locator --dir=" + locatorFolder.getAbsolutePath();
+      gfshRule.execute(stopLocatorCommand);

Review comment:
       Might be good to assert success here.

##########
File path: geode-assembly/src/acceptanceTest/java/org/apache/geode/serialization/filter/LocatorLauncherGlobalSerialFilterAcceptanceTest.java
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.serialization.filter;
+
+import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
+import static org.apache.commons.lang3.JavaVersion.JAVA_9;
+import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
+import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
+import static org.assertj.core.api.Assumptions.assumeThat;
+
+import java.io.File;
+import java.nio.file.Path;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
+import org.apache.geode.rules.ServiceJarRule;
+import org.apache.geode.test.assertj.LogFileAssert;
+import org.apache.geode.test.junit.rules.gfsh.GfshRule;
+
+public class LocatorLauncherGlobalSerialFilterAcceptanceTest {
+
+  @Rule
+  public GfshRule gfshRule = new GfshRule();
+
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Rule
+  public ServiceJarRule serviceJarRule = new ServiceJarRule();
+
+  private File locatorFolder;
+
+  @Test
+  public void startLocatorDoesNotConfigureGlobalSerialFilter_onJava8() {
+    assumeThat(isJavaVersionAtMost(JAVA_1_8)).isTrue();
+
+    locatorFolder = temporaryFolder.getRoot();
+
+    int[] ports = getRandomAvailableTCPPorts(2);
+
+    int locatorPort = ports[0];
+    int locatorJmxPort = ports[1];
+
+    String startLocatorCommand = String.join(" ",
+        "start locator",
+        "--name=locator",
+        "--dir=" + locatorFolder.getAbsolutePath(),
+        "--port=" + locatorPort,
+        "--J=-Dgemfire.jmx-manager-port=" + locatorJmxPort);
+
+    gfshRule.execute(startLocatorCommand);
+
+    try {
+      Path locatorLogFile = locatorFolder.toPath().resolve("locator.log");
+      await().untilAsserted(() -> {
+        LogFileAssert.assertThat(locatorLogFile.toFile()).exists()
+            .doesNotContain("Global serial filter is now configured.")
+            .doesNotContain("jdk.serialFilter");
+      });
+    } finally {
+      String stopLocatorCommand = "stop locator --dir=" + locatorFolder.getAbsolutePath();
+      gfshRule.execute(stopLocatorCommand);
+    }
+  }
+
+  // another test for java 9 that does not create global serial filter
+  @Test
+  public void startLocatorDoesNotConfigureGlobalSerialFilter_onJava9orGreater() {
+    assumeThat(isJavaVersionAtLeast(JAVA_9)).isTrue();
+
+    locatorFolder = temporaryFolder.getRoot();
+
+    int[] ports = getRandomAvailableTCPPorts(2);
+
+    int locatorPort = ports[0];
+    int locatorJmxPort = ports[1];
+
+    String startLocatorCommand = String.join(" ",
+        "start locator",
+        "--name=locator",
+        "--dir=" + locatorFolder.getAbsolutePath(),
+        "--port=" + locatorPort,
+        "--J=-Dgemfire.jmx-manager-port=" + locatorJmxPort);
+
+    gfshRule.execute(startLocatorCommand);
+
+    try {
+      Path locatorLogFile = locatorFolder.toPath().resolve("locator.log");
+      await().untilAsserted(() -> {
+        LogFileAssert.assertThat(locatorLogFile.toFile()).exists()
+            .doesNotContain("Global serial filter is now configured.")
+            .doesNotContain("jdk.serialFilter");
+      });
+    } finally {
+      String stopLocatorCommand = "stop locator --dir=" + locatorFolder.getAbsolutePath();
+      gfshRule.execute(stopLocatorCommand);

Review comment:
       Might be good to assert success here

##########
File path: geode-core/src/integrationTest/java/org/apache/geode/internal/serialization/filter/LocatorLauncherJmxSerialFilterPropertyBlankIntegrationTest.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.internal.serialization.filter;
+
+import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
+import static org.apache.commons.lang3.JavaVersion.JAVA_9;
+import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
+import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtMost;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
+
+import java.io.File;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.rules.TemporaryFolder;
+
+import org.apache.geode.distributed.LocatorLauncher;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.management.ManagementService;
+import org.apache.geode.management.internal.SystemManagementService;
+import org.apache.geode.test.junit.rules.CloseableReference;
+
+public class LocatorLauncherJmxSerialFilterPropertyBlankIntegrationTest {
+
+  private static final String NAME = "locator";
+  private static final String PROPERTY_NAME = "jmx.remote.rmi.server.serial.filter.pattern";
+
+  private File workingDirectory;
+  private int locatorPort;
+  private int jmxPort;
+  private String openMBeanFilterPattern;
+
+  @Rule
+  public CloseableReference<LocatorLauncher> locator = new CloseableReference<>();
+  @Rule
+  public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  @Before
+  public void setUp() throws Exception {
+    openMBeanFilterPattern = new OpenMBeanFilterPattern().pattern();
+    workingDirectory = temporaryFolder.newFolder(NAME);
+    int[] ports = getRandomAvailableTCPPorts(2);
+    locatorPort = ports[0];
+    jmxPort = ports[1];
+  }
+
+  @Test
+  public void configuresJmxSerialFilter_whenPropertyIsBlank_onJava9orGreater() {
+    assumeThat(isJavaVersionAtLeast(JAVA_9)).isTrue();
+
+    System.setProperty(PROPERTY_NAME, " ");
+
+    locator.set(new LocatorLauncher.Builder()
+        .setMemberName(NAME)
+        .setPort(locatorPort)
+        .setWorkingDirectory(workingDirectory.getAbsolutePath())
+        .set(HTTP_SERVICE_PORT, "0")
+        .set(JMX_MANAGER, "true")
+        .set(JMX_MANAGER_PORT, String.valueOf(jmxPort))
+        .set(JMX_MANAGER_START, "true")
+        .set(LOG_FILE, new File(workingDirectory, NAME + ".log").getAbsolutePath())
+        .build())
+        .get()
+        .start();
+
+    assertThat(isJmxManagerStarted())
+        .isTrue();
+    assertThat(System.getProperty(PROPERTY_NAME))
+        .as(PROPERTY_NAME)
+        .isEqualTo(openMBeanFilterPattern);
+  }
+
+  @Test
+  public void doesNotConfigureJmxSerialFilter_whenPropertyIsBlank_onJava8() {

Review comment:
       A lot of these tests look very similar. Could you reduce the amount of code with a parameterized 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.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

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