You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2017/01/09 18:18:03 UTC
[3/4] geode git commit: GEODE-2261: do not use remote function calls
to update the shared configuration
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddJarFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddJarFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddJarFunction.java
deleted file mode 100644
index b986372..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddJarFunction.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.internal.configuration.functions;
-
-import org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-
-public class AddJarFunction extends FunctionAdapter implements InternalEntity {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public AddJarFunction() {}
-
- public void execute(FunctionContext context) {
- InternalLocator locator = InternalLocator.getLocator();
- ConfigurationChangeResult configChangeResult = new ConfigurationChangeResult();
-
- try {
- if (locator.isSharedConfigurationRunning()) {
- final Object[] args = (Object[]) context.getArguments();
- final String[] jarFilenames = (String[]) args[0];
- final byte[][] jarBytes = (byte[][]) args[1];
- final String[] groups = (String[]) args[2];
-
- SharedConfiguration sharedConfiguration = locator.getSharedConfiguration();
- sharedConfiguration.addJarsToThisLocator(jarFilenames, jarBytes, groups);
-
- } else {
- configChangeResult
- .setErrorMessage("Shared Configuration has not been started in locator : " + locator);
- }
- } catch (Exception e) {
- configChangeResult.setException(e);
- configChangeResult.setErrorMessage(CliUtil.stackTraceAsString(e));
- } finally {
- context.getResultSender().lastResult(configChangeResult);
- }
- }
-
- @Override
- public String getId() {
- return AddJarFunction.class.getName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddXmlEntityFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddXmlEntityFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddXmlEntityFunction.java
deleted file mode 100644
index c562c9c..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/AddXmlEntityFunction.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.internal.configuration.functions;
-
-import org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-
-public class AddXmlEntityFunction extends FunctionAdapter implements InternalEntity {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public void execute(FunctionContext context) {
- InternalLocator locator = InternalLocator.getLocator();
- ConfigurationChangeResult configChangeResult = new ConfigurationChangeResult();
- try {
- if (locator.isSharedConfigurationRunning()) {
- Object[] args = (Object[]) context.getArguments();
- XmlEntity xmlEntity = (XmlEntity) args[0];
- String[] groups = (String[]) args[1];
- SharedConfiguration sharedConfig = locator.getSharedConfiguration();
- sharedConfig.addXmlEntity(xmlEntity, groups);
- } else {
- configChangeResult
- .setErrorMessage("Shared Configuration has not been started in locator : " + locator);
- }
- } catch (Exception e) {
- configChangeResult.setException(e);
- configChangeResult.setErrorMessage(CliUtil.stackTraceAsString(e));
- } finally {
- context.getResultSender().lastResult(configChangeResult);
- }
- }
-
- @Override
- public String getId() {
- return AddXmlEntityFunction.class.getName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteJarFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteJarFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteJarFunction.java
deleted file mode 100644
index d0d36a8..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteJarFunction.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.internal.configuration.functions;
-
-import org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-
-public class DeleteJarFunction extends FunctionAdapter implements InternalEntity {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public DeleteJarFunction() {}
-
- @Override
- public void execute(FunctionContext context) {
-
- InternalLocator locator = InternalLocator.getLocator();
- ConfigurationChangeResult configChangeResult = new ConfigurationChangeResult();
-
- try {
- if (locator.isSharedConfigurationRunning()) {
- final Object[] args = (Object[]) context.getArguments();
- final String[] jarFilenames = (String[]) args[0];
- final String[] groups = (String[]) args[1];
-
- SharedConfiguration sharedConfiguration = locator.getSharedConfiguration();
- sharedConfiguration.removeJars(jarFilenames, groups);
- } else {
- configChangeResult
- .setErrorMessage("Shared Configuration has not been started in locator : " + locator);
- }
- } catch (Exception e) {
- configChangeResult.setException(e);
- configChangeResult.setErrorMessage(CliUtil.stackTraceAsString(e));
- } finally {
- context.getResultSender().lastResult(configChangeResult);
- }
- }
-
- @Override
- public String getId() {
- return DeleteJarFunction.class.getName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteXmlEntityFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteXmlEntityFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteXmlEntityFunction.java
deleted file mode 100644
index 1138d5f..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/DeleteXmlEntityFunction.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.internal.configuration.functions;
-
-import org.apache.geode.cache.execute.FunctionAdapter;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-
-public class DeleteXmlEntityFunction extends FunctionAdapter implements InternalEntity {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- @Override
- public void execute(FunctionContext context) {
- InternalLocator locator = InternalLocator.getLocator();
- ConfigurationChangeResult configChangeResult = new ConfigurationChangeResult();
- try {
- if (locator.isSharedConfigurationRunning()) {
- Object[] args = (Object[]) context.getArguments();
- XmlEntity xmlEntity = (XmlEntity) args[0];
- String[] groups = (String[]) args[1];
- SharedConfiguration sharedConfig = locator.getSharedConfiguration();
- sharedConfig.deleteXmlEntity(xmlEntity, groups);
- } else {
- configChangeResult
- .setErrorMessage("Shared Configuration has not been started in locator : " + locator);
- }
- } catch (Exception e) {
- configChangeResult.setException(e);
- configChangeResult.setErrorMessage(CliUtil.stackTraceAsString(e));
-
- } finally {
- context.getResultSender().lastResult(configChangeResult);
-
- }
- }
-
- @Override
- public String getId() {
- return DeleteXmlEntityFunction.class.getName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/ModifyXmlAndPropertiesFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/ModifyXmlAndPropertiesFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/ModifyXmlAndPropertiesFunction.java
deleted file mode 100644
index 97b9ec9..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/ModifyXmlAndPropertiesFunction.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.internal.configuration.functions;
-
-import java.util.Properties;
-
-import org.apache.geode.cache.execute.Function;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.distributed.internal.SharedConfiguration;
-import org.apache.geode.internal.InternalEntity;
-import org.apache.geode.management.internal.cli.CliUtil;
-import org.apache.geode.management.internal.configuration.domain.ConfigurationChangeResult;
-import org.apache.geode.management.internal.configuration.domain.XmlEntity;
-
-public class ModifyXmlAndPropertiesFunction implements Function, InternalEntity {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public void execute(FunctionContext context) {
- InternalLocator locator = InternalLocator.getLocator();
- ConfigurationChangeResult configChangeResult = new ConfigurationChangeResult();
- try {
- if (locator.isSharedConfigurationRunning()) {
- Object[] args = (Object[]) context.getArguments();
- Properties properties = (Properties) args[0];
- XmlEntity xmlEntity = (XmlEntity) args[1];
- String[] groups = (String[]) args[2];
-
- SharedConfiguration sharedConfig = locator.getSharedConfiguration();
- sharedConfig.modifyXmlAndProperties(properties, xmlEntity, groups);
- } else {
- configChangeResult
- .setErrorMessage("Shared Configuration has not been started in locator : " + locator);
- }
- } catch (Exception e) {
- configChangeResult.setException(e);
- configChangeResult.setErrorMessage(CliUtil.stackTraceAsString(e));
- } finally {
- context.getResultSender().lastResult(configChangeResult);
- }
- }
-
- @Override
- public String getId() {
- return ModifyXmlAndPropertiesFunction.class.getName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
index 7ea8682..aa211ac 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/UploadJarFunction.java
@@ -21,10 +21,11 @@ import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.InternalEntity;
-
-import java.io.IOException;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.logging.log4j.Logger;
public class UploadJarFunction implements Function, InternalEntity {
+ private static final Logger logger = LogService.getLogger();
private static final long serialVersionUID = 1L;
@@ -42,10 +43,8 @@ public class UploadJarFunction implements Function, InternalEntity {
byte[] jarBytes = sharedConfig.getJarBytesFromThisLocator(group, jarName);
context.getResultSender().lastResult(jarBytes);
- // TODO: should we just return here if jarbytes was not null?
- } catch (IOException e) {
- context.getResultSender().sendException(e);
} catch (Exception e) {
+ logger.error(e);
context.getResultSender().sendException(e);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/XmlUtils.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/XmlUtils.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/XmlUtils.java
index cad770c..2471c83 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/XmlUtils.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/utils/XmlUtils.java
@@ -465,6 +465,26 @@ public class XmlUtils {
}
/**
+ * Create a {@link Document} using {@link XmlUtils#createDocumentFromXml(String)} and if the
+ * version attribute is not equal to the current version then update the XML to the current schema
+ * and return the document.
+ *
+ * @param xmlContent XML content to load and upgrade.
+ * @return {@link Document} from xmlContent.
+ * @since GemFire 8.1
+ */
+ public static Document createAndUpgradeDocumentFromXml(String xmlContent)
+ throws SAXException, ParserConfigurationException, IOException, XPathExpressionException {
+ Document doc = XmlUtils.createDocumentFromXml(xmlContent);
+ if (!CacheXml.VERSION_LATEST.equals(XmlUtils.getAttribute(doc.getDocumentElement(),
+ CacheXml.VERSION, CacheXml.GEODE_NAMESPACE))) {
+ doc = upgradeSchema(doc, CacheXml.GEODE_NAMESPACE, CacheXml.LATEST_SCHEMA_LOCATION,
+ CacheXml.VERSION_LATEST);
+ }
+ return doc;
+ }
+
+ /**
* Upgrade the schema of a given Config XMl <code>document</code> to the given
* <code>namespace</code>, <code>schemaLocation</code> and <code>version</code>.
*
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.java
deleted file mode 100644
index e3e5620..0000000
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/SharedConfigurationJUnitTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.distributed.internal;
-
-import static org.apache.geode.management.internal.configuration.utils.XmlConstants.*;
-import static javax.xml.XMLConstants.*;
-import static org.junit.Assert.*;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.w3c.dom.Document;
-
-import org.apache.geode.internal.cache.xmlcache.CacheXml;
-import org.apache.geode.management.internal.configuration.utils.XmlUtils;
-import org.apache.geode.test.junit.categories.UnitTest;
-
-/**
- * Unit tests for {@link SharedConfiguration}.
- *
- * @since GemFire 8.1
- */
-@Category(UnitTest.class)
-public class SharedConfigurationJUnitTest {
-
- @Test
- public void testCreateAndUpgradeDocumentFromXml() throws Exception {
- Document doc = SharedConfiguration.createAndUpgradeDocumentFromXml(
- IOUtils.toString(this.getClass().getResourceAsStream("SharedConfigurationJUnitTest.xml")));
-
- String schemaLocation = XmlUtils.getAttribute(doc.getDocumentElement(),
- W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, W3C_XML_SCHEMA_INSTANCE_NS_URI);
-
- assertNotNull(schemaLocation);
- assertEquals(CacheXml.GEODE_NAMESPACE + " " + CacheXml.LATEST_SCHEMA_LOCATION, schemaLocation);
-
- assertEquals(CacheXml.VERSION_LATEST,
- XmlUtils.getAttribute(doc.getDocumentElement(), "version"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/internal/cache/extension/mock/MockExtensionCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/extension/mock/MockExtensionCommands.java b/geode-core/src/test/java/org/apache/geode/internal/cache/extension/mock/MockExtensionCommands.java
index e2a56fd..1bd4478 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/extension/mock/MockExtensionCommands.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/extension/mock/MockExtensionCommands.java
@@ -17,6 +17,7 @@ package org.apache.geode.internal.cache.extension.mock;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
@@ -28,10 +29,10 @@ import org.apache.geode.management.cli.CliMetaData;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.cli.Result.Status;
import org.apache.geode.management.internal.cli.CliUtil;
+import org.apache.geode.management.internal.cli.commands.AbstractCommandsSupport;
import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
import org.apache.geode.management.internal.cli.result.ResultBuilder;
import org.apache.geode.management.internal.cli.result.TabularResultData;
-import org.apache.geode.management.internal.configuration.SharedConfigurationWriter;
import org.apache.geode.management.internal.configuration.domain.XmlEntity;
import org.apache.geode.management.internal.security.ResourceOperation;
import org.apache.geode.security.ResourcePermission.Operation;
@@ -47,7 +48,7 @@ import org.springframework.shell.core.annotation.CliOption;
*
* @since GemFire 8.1
*/
-public class MockExtensionCommands implements CommandMarker {
+public class MockExtensionCommands extends AbstractCommandsSupport {
public static final String OPTION_VALUE = "value";
@@ -191,7 +192,7 @@ public class MockExtensionCommands implements CommandMarker {
final List<CliFunctionResult> functionResults =
(List<CliFunctionResult>) resultCollector.getResult();
- XmlEntity xmlEntity = null;
+ AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
final TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
final String errorPrefix = "ERROR: ";
for (CliFunctionResult functionResult : functionResults) {
@@ -199,7 +200,7 @@ public class MockExtensionCommands implements CommandMarker {
tabularResultData.accumulate("Member", functionResult.getMemberIdOrName());
if (success) {
tabularResultData.accumulate("Status", functionResult.getMessage());
- xmlEntity = functionResult.getXmlEntity();
+ xmlEntity.set(functionResult.getXmlEntity());
} else {
tabularResultData.accumulate("Status", errorPrefix + functionResult.getMessage());
tabularResultData.setStatus(Status.ERROR);
@@ -209,12 +210,13 @@ public class MockExtensionCommands implements CommandMarker {
final Result result = ResultBuilder.buildResult(tabularResultData);
System.out.println("MockExtensionCommands: persisting xmlEntity=" + xmlEntity);
- if (null != xmlEntity) {
+ if (null != xmlEntity.get()) {
if (addXmlElement) {
- result.setCommandPersisted((new SharedConfigurationWriter()).addXmlEntity(xmlEntity, null));
+ persistClusterConfiguration(result,
+ () -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), null));
} else {
- result.setCommandPersisted(
- (new SharedConfigurationWriter()).deleteXmlEntity(xmlEntity, null));
+ persistClusterConfiguration(result,
+ () -> getSharedConfiguration().deleteXmlEntity(xmlEntity.get(), null));
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
index d86cb0b..87e6f66 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java
@@ -14,6 +14,33 @@
*/
package org.apache.geode.management.internal.cli.commands;
+import static org.apache.commons.io.FileUtils.deleteDirectory;
+import static org.apache.geode.distributed.ConfigurationProperties.ARCHIVE_FILE_SIZE_LIMIT;
+import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_CONFIGURATION_DIR;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_TIME_STATISTICS;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+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_BIND_ADDRESS;
+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.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_SAMPLING_ENABLED;
+import static org.apache.geode.internal.AvailablePort.SOCKET;
+import static org.apache.geode.internal.AvailablePort.getRandomAvailablePort;
+import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.test.dunit.Wait.waitForCriterion;
+
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.distributed.Locator;
@@ -21,6 +48,7 @@ import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.distributed.internal.SharedConfiguration;
+import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
import org.apache.geode.internal.logging.LogWriterImpl;
@@ -30,28 +58,29 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.remote.CommandProcessor;
import org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
-import org.apache.geode.test.dunit.*;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.SerializableCallable;
+import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.WaitCriterion;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.categories.FlakyTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import java.io.*;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.internal.AvailablePort.SOCKET;
-import static org.apache.geode.internal.AvailablePort.getRandomAvailablePort;
-import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts;
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-import static org.apache.commons.io.FileUtils.deleteDirectory;
-
/**
* Dunit class for testing GemFire config commands : export config
*
@@ -426,22 +455,34 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
@Test
public void testAlterUpdatesSharedConfig() throws Exception {
final String groupName = getName();
+ final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+ jmxPort = ports[0];
+ httpPort = ports[1];
+ try {
+ jmxHost = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException ignore) {
+ jmxHost = "localhost";
+ }
// Start the Locator and wait for shared configuration to be available
final int locatorPort = getRandomAvailablePort(SOCKET);
final String locatorDirectory = this.temporaryFolder.newFolder("Locator").getAbsolutePath();
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, "Locator");
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR, locatorDirectory);
+ locatorProps.setProperty(JMX_MANAGER, "true");
+ locatorProps.setProperty(JMX_MANAGER_START, "true");
+ locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+ locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+ locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
final File locatorLogFile = new File(locatorDirectory, "locator-" + locatorPort + ".log");
-
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, "Locator");
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
- locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR, locatorDirectory);
-
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
locatorLogFile, null, locatorProps);
@@ -465,11 +506,7 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
}
});
- // Start the default manager
- Properties managerProps = new Properties();
- managerProps.setProperty(MCAST_PORT, "0");
- managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
- setUpJmxManagerOnVm0ThenConnect(managerProps);
+ connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
@@ -499,7 +536,7 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the shared config was updated
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
SharedConfiguration sharedConfig =
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
index 7a75cfa..f910721 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsDUnitTest.java
@@ -14,33 +14,36 @@
*/
package org.apache.geode.management.internal.cli.commands;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.LogWriterUtils.*;
-import static com.jayway.awaitility.Awaitility.*;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.TimeUnit;
-
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.apache.geode.cache.*;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.internal.cache.PartitionedRegion;
+import static com.jayway.awaitility.Awaitility.waitAtMost;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+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_BIND_ADDRESS;
+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.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.PartitionAttributes;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.PartitionResolver;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.Scope;
import org.apache.geode.cache.asyncqueue.AsyncEvent;
import org.apache.geode.cache.asyncqueue.AsyncEventListener;
import org.apache.geode.cache.wan.GatewaySenderFactory;
@@ -49,9 +52,13 @@ import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.AvailablePort;
+import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.ClassBuilder;
import org.apache.geode.internal.FileUtil;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.PartitionedRegion;
import org.apache.geode.internal.cache.RegionEntryContext;
+import org.apache.geode.management.ManagementService;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.MBeanJMXAdapter;
import org.apache.geode.management.internal.ManagementConstants;
@@ -63,6 +70,26 @@ import org.apache.geode.test.dunit.SerializableCallable;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.categories.FlakyTest;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
@Category(DistributedTest.class)
public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBase {
@@ -839,8 +866,17 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
*/
@Category(FlakyTest.class) // GEODE-2009
@Test
- public void testCreateAlterDestroyUpdatesSharedConfig() {
+ public void testCreateAlterDestroyUpdatesSharedConfig() throws Exception {
disconnectAllFromDS();
+ final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+ jmxPort = ports[0];
+ httpPort = ports[1];
+ try {
+ jmxHost = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException ignore) {
+ jmxHost = "localhost";
+ }
+
final String regionName = "testRegionSharedConfigRegion";
final String regionPath = "/" + regionName;
@@ -848,28 +884,38 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
- Host.getHost(0).getVM(3).invoke(() -> {
+
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, "Locator");
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "fine");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(JMX_MANAGER, "true");
+ locatorProps.setProperty(JMX_MANAGER_START, "true");
+ locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+ locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+ locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+ Host.getHost(0).getVM(0).invoke(() -> {
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, "Locator");
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "fine");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
locatorLogFile, null, locatorProps);
waitAtMost(5, TimeUnit.SECONDS).until(() -> locator.isSharedConfigurationRunning());
+
+ ManagementService managementService =
+ ManagementService.getExistingManagementService(GemFireCacheImpl.getInstance());
+ assertNotNull(managementService);
+ assertTrue(managementService.isManager());
+ assertTrue(checkIfCommandsAreLoadedOrNot());
+
} catch (IOException ioex) {
fail("Unable to create a locator with a shared configuration");
}
});
- // Start the default manager
- Properties managerProps = new Properties();
- managerProps.setProperty(MCAST_PORT, "0");
- managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
- setUpJmxManagerOnVm0ThenConnect(managerProps);
+ connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
@@ -895,7 +941,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
waitForRegionMBeanCreation(regionPath, 1);
// Make sure the region exists in the shared config
- Host.getHost(0).getVM(3).invoke(() -> {
+ Host.getHost(0).getVM(0).invoke(() -> {
SharedConfiguration sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
@@ -937,7 +983,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the region was altered in the shared config
- Host.getHost(0).getVM(3).invoke(() -> {
+ Host.getHost(0).getVM(0).invoke(() -> {
SharedConfiguration sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
@@ -976,22 +1022,38 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
@Test
public void testDestroyRegionWithSharedConfig() {
-
disconnectAllFromDS();
+ final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+ jmxPort = ports[0];
+ httpPort = ports[1];
+ try {
+ jmxHost = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException ignore) {
+ jmxHost = "localhost";
+ }
+
+
final String regionName = "testRegionSharedConfigRegion";
final String regionPath = "/" + regionName;
final String groupName = "testRegionSharedConfigGroup";
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
- Host.getHost(0).getVM(3).invoke(() -> {
+
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, "Locator");
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "fine");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(JMX_MANAGER, "true");
+ locatorProps.setProperty(JMX_MANAGER_START, "true");
+ locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+ locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+ locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+ Host.getHost(0).getVM(0).invoke(() -> {
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, "Locator");
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "fine");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
locatorLogFile, null, locatorProps);
@@ -1002,11 +1064,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
}
});
- // Start the default manager
- Properties managerProps = new Properties();
- managerProps.setProperty(MCAST_PORT, "0");
- managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
- setUpJmxManagerOnVm0ThenConnect(managerProps);
+ connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
@@ -1032,7 +1090,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
waitForRegionMBeanCreation(regionPath, 1);
// Make sure the region exists in the shared config
- Host.getHost(0).getVM(3).invoke(() -> {
+ Host.getHost(0).getVM(0).invoke(() -> {
SharedConfiguration sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
@@ -1051,7 +1109,7 @@ public class CreateAlterDestroyRegionCommandsDUnitTest extends CliCommandTestBas
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the region was removed from the shared config
- Host.getHost(0).getVM(3).invoke(() -> {
+ Host.getHost(0).getVM(0).invoke(() -> {
SharedConfiguration sharedConfig =
((InternalLocator) Locator.getLocator()).getSharedConfiguration();
try {
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
index 7cf9a3a..34ffc7c 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DeployCommandsDUnitTest.java
@@ -14,11 +14,28 @@
*/
package org.apache.geode.management.internal.cli.commands;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+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_BIND_ADDRESS;
+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_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.DistributionManager;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.AvailablePort;
+import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.ClassBuilder;
import org.apache.geode.internal.JarDeployer;
import org.apache.geode.management.cli.Result;
@@ -26,7 +43,13 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.remote.CommandExecutionContext;
import org.apache.geode.management.internal.cli.remote.CommandProcessor;
import org.apache.geode.management.internal.cli.result.CommandResult;
-import org.apache.geode.test.dunit.*;
+import org.apache.geode.test.dunit.Assert;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.Wait;
+import org.apache.geode.test.dunit.WaitCriterion;
+import org.apache.geode.test.dunit.rules.ServerStarterRule;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -34,12 +57,11 @@ import org.junit.experimental.categories.Category;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Properties;
import java.util.regex.Pattern;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.test.dunit.Assert.*;
-
/**
* Unit tests for the DeployCommands class
*
@@ -315,24 +337,35 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
@Test
public void testEndToEnd() throws Exception {
final String groupName = getName();
+ final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+ jmxPort = ports[0];
+ httpPort = ports[1];
+ try {
+ jmxHost = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException ignore) {
+ jmxHost = "localhost";
+ }
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
+ "locator-" + locatorPort + ".log";
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, "Locator");
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "fine");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(JMX_MANAGER, "true");
+ locatorProps.setProperty(JMX_MANAGER_START, "true");
+ locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+ locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+ locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
-
final File locatorLogFile = new File(locatorLogPath);
-
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, "Locator");
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "fine");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
-
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
locatorLogFile, null, locatorProps);
@@ -356,12 +389,15 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
}
});
- // Start the default manager
- Properties managerProps = new Properties();
- managerProps.setProperty(MCAST_PORT, "0");
- managerProps.setProperty(GROUPS, groupName);
- managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
- setUpJmxManagerOnVm0ThenConnect(managerProps);
+ connect(jmxHost, jmxPort, httpPort, getDefaultShell());
+
+ Host.getHost(0).getVM(1).invoke(() -> {
+ Properties properties = new Properties();
+ properties.setProperty("name", "Manager");
+ properties.setProperty("groups", groupName);
+ ServerStarterRule serverStarterRule = new ServerStarterRule(properties);
+ serverStarterRule.startServer(locatorPort);
+ });
// Create a JAR file
this.classBuilder.writeJarFromName("DeployCommandsDUnitA", this.newDeployableJarFile);
@@ -383,23 +419,29 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
- assertTrue(stringContainsLine(stringResult, "Member.*JAR.*Un-Deployed From JAR Location"));
- assertTrue(stringContainsLine(stringResult, "Manager.*DeployCommandsDUnit1.jar.*"
- + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1"));
+ assertThat(stringContainsLine(stringResult, "Member.*JAR.*Un-Deployed From JAR Location"))
+ .describedAs(stringResult).isTrue();
+ assertThat(stringContainsLine(stringResult, "Manager.*DeployCommandsDUnit1.jar.*"
+ + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1")).describedAs(stringResult)
+ .isTrue();;
+
// Deploy the JAR to a group
cmdResult = executeCommand(
"deploy --jar=" + this.newDeployableJarFile.getCanonicalPath() + " --group=" + groupName);
- assertEquals(Result.Status.OK, cmdResult.getStatus());
+ assertThat(cmdResult.getStatus()).describedAs(cmdResult.toString()).isEqualTo(Result.Status.OK);
stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
- assertTrue(stringContainsLine(stringResult, "Member.*JAR.*JAR Location"));
- assertTrue(stringContainsLine(stringResult, "Manager.*DeployCommandsDUnit1.jar.*"
- + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1"));
+ assertThat(stringContainsLine(stringResult, "Member.*JAR.*JAR Location"))
+ .describedAs(stringResult).isTrue();
+
+ assertThat(stringContainsLine(stringResult, "Manager.*DeployCommandsDUnit1.jar.*"
+ + JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1")).describedAs(stringResult)
+ .isTrue();
// Make sure the deployed jar in the shared config
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
SharedConfiguration sharedConfig =
@@ -434,7 +476,7 @@ public class DeployCommandsDUnitTest extends CliCommandTestBase {
+ JarDeployer.JAR_PREFIX + "DeployCommandsDUnit1.jar#1"));
// Make sure the deployed jar was removed from the shared config
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
SharedConfiguration sharedConfig =
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
index 901ed29..a04bbe8 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
@@ -16,6 +16,11 @@ package org.apache.geode.management.internal.cli.commands;
import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+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_BIND_ADDRESS;
+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.LOCATORS;
import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
@@ -30,18 +35,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.TimeUnit;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
@@ -86,6 +79,19 @@ import org.apache.geode.test.junit.categories.FlakyTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+
/**
* The DiskStoreCommandsDUnitTest class is a distributed test suite of test cases for testing the
* disk store commands that are part of Gfsh.
@@ -722,22 +728,35 @@ public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
@Test
public void testCreateDestroyUpdatesSharedConfig() {
disconnectAllFromDS();
+ final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+ jmxPort = ports[0];
+ httpPort = ports[1];
+ try {
+ jmxHost = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException ignore) {
+ jmxHost = "localhost";
+ }
final String groupName = "testDiskStoreSharedConfigGroup";
final String diskStoreName = "testDiskStoreSharedConfigDiskStore";
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, "Locator");
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "fine");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(JMX_MANAGER, "true");
+ locatorProps.setProperty(JMX_MANAGER_START, "true");
+ locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+ locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+ locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
-
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, "Locator");
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "fine");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
locatorLogFile, null, locatorProps);
@@ -760,11 +779,7 @@ public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
}
});
- // Start the default manager
- Properties managerProps = new Properties();
- managerProps.setProperty(MCAST_PORT, "0");
- managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
- setUpJmxManagerOnVm0ThenConnect(managerProps);
+ connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
final File diskStoreDir = new File(new File(".").getAbsolutePath(), diskStoreName);
@@ -795,7 +810,7 @@ public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the disk store exists in the shared config
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
SharedConfiguration sharedConfig =
@@ -847,7 +862,7 @@ public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the disk store was removed from the shared config
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
SharedConfiguration sharedConfig =
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
index 6dbd10c..81c4545 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsDUnitTest.java
@@ -14,19 +14,52 @@
*/
package org.apache.geode.management.internal.cli.commands;
-import org.apache.geode.cache.*;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+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_BIND_ADDRESS;
+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.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.DiskStoreFactory;
+import org.apache.geode.cache.EvictionAction;
+import org.apache.geode.cache.EvictionAttributes;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
import org.apache.geode.cache.query.Index;
import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.AvailablePort;
+import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.cli.Result.Status;
import org.apache.geode.management.internal.cli.domain.Stock;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
-import org.apache.geode.test.dunit.*;
+import org.apache.geode.test.dunit.Assert;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.LogWriterUtils;
+import org.apache.geode.test.dunit.SerializableCallable;
+import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.Wait;
+import org.apache.geode.test.dunit.WaitCriterion;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.categories.FlakyTest;
import org.junit.Test;
@@ -34,11 +67,10 @@ import org.junit.experimental.categories.Category;
import java.io.File;
import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Properties;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.test.dunit.Assert.*;
-
@Category(DistributedTest.class)
public class IndexCommandsDUnitTest extends CliCommandTestBase {
@@ -595,22 +627,35 @@ public class IndexCommandsDUnitTest extends CliCommandTestBase {
@Test
public void testCreateDestroyUpdatesSharedConfig() {
disconnectAllFromDS();
+ final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+ jmxPort = ports[0];
+ httpPort = ports[1];
+ try {
+ jmxHost = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException ignore) {
+ jmxHost = "localhost";
+ }
final String regionName = "testIndexSharedConfigRegion";
final String groupName = "testIndexSharedConfigGroup";
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, "Locator");
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "fine");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(JMX_MANAGER, "true");
+ locatorProps.setProperty(JMX_MANAGER_START, "true");
+ locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+ locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+ locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
-
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, "Locator");
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "fine");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
locatorLogFile, null, locatorProps);
@@ -634,10 +679,7 @@ public class IndexCommandsDUnitTest extends CliCommandTestBase {
});
// Start the default manager
- Properties managerProps = new Properties();
- managerProps.setProperty(MCAST_PORT, "0");
- managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
- setUpJmxManagerOnVm0ThenConnect(managerProps);
+ connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
@@ -666,7 +708,7 @@ public class IndexCommandsDUnitTest extends CliCommandTestBase {
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the index exists in the shared config
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
SharedConfiguration sharedConfig =
@@ -712,7 +754,7 @@ public class IndexCommandsDUnitTest extends CliCommandTestBase {
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the index was removed from the shared config
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
SharedConfiguration sharedConfig =
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
index b1897ba..98014a4 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/QueueCommandsDUnitTest.java
@@ -14,7 +14,25 @@
*/
package org.apache.geode.management.internal.cli.commands;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+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_BIND_ADDRESS;
+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.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.NAME;
+import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertFalse;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Assert.assertTrue;
+import static org.apache.geode.test.dunit.Assert.fail;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.test.dunit.Wait.waitForCriterion;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
@@ -22,6 +40,7 @@ import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.distributed.internal.SharedConfiguration;
import org.apache.geode.internal.AvailablePort;
+import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.ClassBuilder;
import org.apache.geode.internal.FileUtil;
import org.apache.geode.management.cli.Result;
@@ -41,16 +60,12 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.CopyOnWriteArrayList;
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.apache.geode.test.dunit.Assert.*;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-
/**
* A distributed test suite of test cases for testing the queue commands that are part of Gfsh.
*
@@ -257,22 +272,36 @@ public class QueueCommandsDUnitTest extends CliCommandTestBase {
@Test
public void testCreateUpdatesSharedConfig() throws IOException {
disconnectAllFromDS();
+ final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+ jmxPort = ports[0];
+ httpPort = ports[1];
+ try {
+ jmxHost = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException ignore) {
+ jmxHost = "localhost";
+ }
final String queueName = "testAsyncEventQueueQueue";
final String groupName = "testAsyncEventQueueSharedConfigGroup";
+ final Properties locatorProps = new Properties();
+ locatorProps.setProperty(NAME, "Locator");
+ locatorProps.setProperty(MCAST_PORT, "0");
+ locatorProps.setProperty(LOG_LEVEL, "fine");
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+ locatorProps.setProperty(JMX_MANAGER, "true");
+ locatorProps.setProperty(JMX_MANAGER_START, "true");
+ locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
+ locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
+ locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
+
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
-
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, "Locator");
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "fine");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
+
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
locatorLogFile, null, locatorProps);
@@ -295,11 +324,7 @@ public class QueueCommandsDUnitTest extends CliCommandTestBase {
}
});
- // Start the default manager
- Properties managerProps = new Properties();
- managerProps.setProperty(MCAST_PORT, "0");
- managerProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
- setUpJmxManagerOnVm0ThenConnect(managerProps);
+ connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
@@ -347,7 +372,7 @@ public class QueueCommandsDUnitTest extends CliCommandTestBase {
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the queue exists in the shared config
- Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
+ Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
SharedConfiguration sharedConfig =
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
index 28890b8..506428a 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigBaseTest.java
@@ -57,9 +57,10 @@ public class ClusterConfigBaseTest extends JUnit4DistributedTestCase {
@Before
public void before() throws Exception {
locatorProps = new Properties();
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
-
serverProps = new Properties();
+
+ // the following are default values, we don't need to set them. We do it for clarity purpose
+ locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
serverProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
index a501235..51a77d2 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDeployJarDUnitTest.java
@@ -66,7 +66,7 @@ public class ClusterConfigDeployJarDUnitTest extends ClusterConfigBaseTest {
}
@Test
- public void testDeployToMultipleLocaotrs() throws Exception {
+ public void testDeployToMultipleLocators() throws Exception {
Locator locator = lsRule.startLocatorVM(0, locatorProps);
locatorProps.setProperty(LOCATORS, "localhost[" + locator.getPort() + "]");
Locator locator2 = lsRule.startLocatorVM(1, locatorProps);
http://git-wip-us.apache.org/repos/asf/geode/blob/602ac4f4/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java
new file mode 100644
index 0000000..d72e386
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigDistributionDUnitTest.java
@@ -0,0 +1,164 @@
+/*
+ * 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.internal.configuration;
+
+import static org.apache.commons.io.FileUtils.writeByteArrayToFile;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
+import org.apache.geode.cache.query.Index;
+import org.apache.geode.internal.ClassBuilder;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
+import org.apache.geode.test.dunit.rules.Locator;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.Server;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+@Category(DistributedTest.class)
+public class ClusterConfigDistributionDUnitTest extends JUnit4DistributedTestCase {
+ private static final String REPLICATE_REGION = "ReplicateRegion1";
+ private static final String PARTITION_REGION = "PartitionRegion1";
+ private static final String INDEX1 = "ID1";
+ private static final String INDEX2 = "ID2";
+ private static final String AsyncEventQueue1 = "Q1";
+
+ private Locator locator;
+ private GfshShellConnectionRule gfshConnector;
+
+ @Before
+ public void before() throws Exception {
+ locator = lsRule.startLocatorVM(0);
+
+ gfshConnector = new GfshShellConnectionRule(locator);
+ gfshConnector.connect();
+ assertThat(gfshConnector.isConnected()).isTrue();
+ }
+
+ @Rule
+ public LocatorServerStartupRule lsRule = new LocatorServerStartupRule();
+
+ @Test
+ public void testIndexAndAsyncEventQueueCommands() throws Exception {
+ lsRule.startServerVM(1, locator.getPort());
+
+ final String DESTROY_REGION = "regionToBeDestroyed";
+
+ gfshConnector
+ .executeAndVerifyCommand("create region --name=" + REPLICATE_REGION + " --type=REPLICATE");
+ gfshConnector
+ .executeAndVerifyCommand("create region --name=" + PARTITION_REGION + " --type=PARTITION");
+ gfshConnector
+ .executeAndVerifyCommand("create region --name=" + DESTROY_REGION + " --type=REPLICATE");
+
+ gfshConnector.executeAndVerifyCommand(
+ "create index --name=" + INDEX1 + " --expression=AAPL --region=" + REPLICATE_REGION);
+ gfshConnector.executeAndVerifyCommand(
+ "create index --name=" + INDEX2 + " --expression=VMW --region=" + PARTITION_REGION);
+
+
+ String asyncEventQueueJarPath = createAsyncEventQueueJar();
+ gfshConnector.executeAndVerifyCommand("deploy jar --jar=" + asyncEventQueueJarPath);
+
+
+ CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, AsyncEventQueue1);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER,
+ "com.qcdunit.QueueCommandsDUnitTestListener");
+ csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISK_STORE, null);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE, "1000");
+ csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP, null);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__PERSISTENT, "false");
+ csb.addOptionWithValueCheck(CliStrings.CREATE_ASYNC_EVENT_QUEUE__MAXIMUM_QUEUE_MEMORY, "1000");
+ gfshConnector.executeAndVerifyCommand(csb.getCommandString());
+
+ gfshConnector.executeAndVerifyCommand("destroy region --name=" + DESTROY_REGION);
+
+ gfshConnector.executeAndVerifyCommand(
+ "destroy index --name=" + INDEX2 + " --region=" + PARTITION_REGION);
+ gfshConnector.executeAndVerifyCommand("alter runtime --copy-on-read=true");
+
+ // Start a new member which receives the shared configuration
+ // Verify the config creation on this member
+
+ Server server = lsRule.startServerVM(2, new Properties(), locator.getPort());
+
+ server.invoke(() -> {
+ Cache cache = LocatorServerStartupRule.serverStarter.cache;
+ assertNotNull(cache);
+ assertTrue(cache.getCopyOnRead());
+
+ Region region1 = cache.getRegion(REPLICATE_REGION);
+ assertNotNull(region1);
+ Region region2 = cache.getRegion(PARTITION_REGION);
+ assertNotNull(region2);
+
+ Region region3 = cache.getRegion(DESTROY_REGION);
+ assertNull(region3);
+
+ // Index verification
+ Index index1 = cache.getQueryService().getIndex(region1, INDEX1);
+ assertNotNull(index1);
+ assertNull(cache.getQueryService().getIndex(region2, INDEX2));
+
+ // ASYNC-EVENT-QUEUE verification
+ AsyncEventQueue aeq = cache.getAsyncEventQueue(AsyncEventQueue1);
+ assertNotNull(aeq);
+ assertFalse(aeq.isPersistent());
+ assertTrue(aeq.getBatchSize() == 1000);
+ assertTrue(aeq.getMaximumQueueMemory() == 1000);
+ });
+ }
+
+
+ private String createAsyncEventQueueJar() throws IOException {
+ String queueCommandsJarName = this.lsRule.getTempFolder().getRoot().getCanonicalPath()
+ + File.separator + "testEndToEndSC-QueueCommands.jar";
+ final File jarFile = new File(queueCommandsJarName);
+
+ ClassBuilder classBuilder = new ClassBuilder();
+ byte[] jarBytes =
+ classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener",
+ "package com.qcdunit;" + "import java.util.List; import java.util.Properties;"
+ + "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;"
+ + "import org.apache.geode.cache.asyncqueue.AsyncEventListener;"
+ + "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {"
+ + "Properties props;"
+ + "public boolean processEvents(List<AsyncEvent> events) { return true; }"
+ + "public void close() {}"
+ + "public void init(final Properties props) {this.props = props;}"
+ + "public Properties getConfig() {return this.props;}}");
+
+ writeByteArrayToFile(jarFile, jarBytes);
+ return queueCommandsJarName;
+ }
+}