This is an automated email from the ASF dual-hosted git repository. upthewaterspout pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push: new 8064aa3 GEODE-5396: A bit of restructuring and a bit of cleanup to isolate failures better 8064aa3 is described below commit 8064aa3eeb8ec387486c4ffe60dbeb30384b154e Author: Mark Hanson <mhan...@pivotal.io> AuthorDate: Thu Jul 12 14:11:00 2018 -0700 GEODE-5396: A bit of restructuring and a bit of cleanup to isolate failures better --- .../org/apache/geode/tools/pulse/tests/Server.java | 196 +++++++++++---------- .../geode/tools/pulse/tests/rules/ServerRule.java | 80 ++++----- .../tools/pulse/tests/rules/WebDriverRule.java | 43 +++-- .../geode/tools/pulse/tests/ui/PulseTestUtils.java | 11 +- 4 files changed, 175 insertions(+), 155 deletions(-) diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/Server.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/Server.java index 44b694f..a4cec43 100644 --- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/Server.java +++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/Server.java @@ -16,7 +16,6 @@ package org.apache.geode.tools.pulse.tests; import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANAGER; -import java.io.IOException; import java.lang.management.ManagementFactory; import java.net.Inet4Address; import java.net.Inet6Address; @@ -26,8 +25,10 @@ import java.rmi.registry.LocateRegistry; import java.util.HashMap; import java.util.Map; import java.util.Properties; +import java.util.concurrent.TimeUnit; import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; @@ -37,6 +38,8 @@ import javax.management.remote.JMXConnectorServer; import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXServiceURL; +import org.awaitility.Awaitility; + import org.apache.geode.internal.security.SecurityService; import org.apache.geode.internal.security.SecurityServiceFactory; import org.apache.geode.internal.security.shiro.JMXShiroAuthenticator; @@ -53,12 +56,43 @@ public class Server { private final JMXServiceURL url; private MBeanServer mbs; private JMXConnectorServer cs; - private String propFile = null; + private String propFile; + private int jmxPort; + private String jsonAuthFile; public Server(int jmxPort, String properties, String jsonAuthFile) throws Exception { this.propFile = properties; mbs = ManagementFactory.getPlatformMBeanServer(); url = new JMXServiceURL(formJMXServiceURLString(DEFAULT_HOST, jmxPort)); + this.jmxPort = jmxPort; + this.jsonAuthFile = jsonAuthFile; + } + + private String formJMXServiceURLString(String host, int jmxPort) throws UnknownHostException { + String jmxSerURL = ""; + + InetAddress inetAddr = InetAddress.getByName(host); + if (inetAddr instanceof Inet4Address) { + // Create jmx service url for IPv4 address + jmxSerURL = "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi"; + } else if (inetAddr instanceof Inet6Address) { + // Create jmx service url for IPv6 address + jmxSerURL = + "service:jmx:rmi://[" + host + "]/jndi/rmi://[" + host + "]:" + jmxPort + "/jmxrmi"; + } + + return jmxSerURL; + } + + public void stop() throws Exception { + cs.stop(); + unloadMBeans(); + + if (jsonAuthFile != null) + mbs.unregisterMBean(new ObjectName(ResourceConstants.OBJECT_NAME_ACCESSCONTROL)); + } + + public void start() throws Exception { // Load the beans first, otherwise we get access denied loadMBeans(); @@ -66,7 +100,7 @@ public class Server { if (jsonAuthFile != null) { System.setProperty("spring.profiles.active", "pulse.authentication.gemfire"); - Map<String, Object> env = new HashMap<String, Object>(); + Map<String, Object> env = new HashMap<>(); // set up Shiro Security Manager Properties securityProperties = new Properties(); @@ -75,20 +109,15 @@ public class Server { SecurityService securityService = SecurityServiceFactory.create(securityProperties); - // register the AccessControll bean - AccessControlMBean acc = new AccessControlMBean(securityService); - ObjectName accessControlMBeanON = new ObjectName(ResourceConstants.OBJECT_NAME_ACCESSCONTROL); - MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); - platformMBeanServer.registerMBean(acc, accessControlMBeanON); + // register the AccessControl bean + mbs.registerMBean(new AccessControlMBean(securityService), + new ObjectName(ResourceConstants.OBJECT_NAME_ACCESSCONTROL)); - // wire in the authenticator and authorizaton - JMXShiroAuthenticator interceptor = new JMXShiroAuthenticator(securityService); - env.put(JMXConnectorServer.AUTHENTICATOR, interceptor); + // wire in the authenticator and authorization + env.put(JMXConnectorServer.AUTHENTICATOR, new JMXShiroAuthenticator(securityService)); cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); cs.setMBeanServerForwarder(new MBeanServerWrapper(securityService)); - // set up the AccessControlMXBean - } else { System.setProperty("spring.profiles.active", "pulse.authentication.default"); cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); @@ -99,105 +128,80 @@ public class Server { System.out.println("RMI registry ready."); } catch (Exception e) { System.out.println("Exception starting RMI registry:"); - e.printStackTrace(); + throw e; } cs.start(); + Awaitility.waitAtMost(30, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS) + .until(() -> cs.isActive()); } - private String formJMXServiceURLString(String host, int jmxPort) throws UnknownHostException { - String jmxSerURL = ""; + private synchronized void loadMBeans() throws Exception { + JMXProperties props = JMXProperties.getInstance(); - InetAddress inetAddr = InetAddress.getByName(host); - if (inetAddr instanceof Inet4Address) { - // Create jmx service url for IPv4 address - jmxSerURL = "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi"; - } else if (inetAddr instanceof Inet6Address) { - // Create jmx service url for IPv6 address - jmxSerURL = - "service:jmx:rmi://[" + host + "]/jndi/rmi://[" + host + "]:" + jmxPort + "/jmxrmi"; + props.load(propFile); + + // Add servers + String[] servers = getArrayProperty(props, "servers"); + for (String server : servers) { + addServerMBean(server); } - return jmxSerURL; - } + // Add members + String[] members = getArrayProperty(props, "members"); + for (String m : members) { + addMemberMBean(m); + } - public void stop() throws IOException { - cs.stop(); + // Add regions + String[] regions = getArrayProperty(props, "regions"); + for (String reg : regions) { + addRegionMBean(reg); + } } - private synchronized void loadMBeans() { + private synchronized void unloadMBeans() throws Exception { JMXProperties props = JMXProperties.getInstance(); - try { - props.load(propFile); - } catch (IOException e) { - e.printStackTrace(); - } - // Add servers + props.load(propFile); + + // remove servers String[] servers = getArrayProperty(props, "servers"); for (String server : servers) { - try { - addServerMBean(server); - } catch (InstanceAlreadyExistsException e) { - e.printStackTrace(); - } catch (MBeanRegistrationException e) { - e.printStackTrace(); - } catch (NotCompliantMBeanException e) { - e.printStackTrace(); - } catch (MalformedObjectNameException e) { - e.printStackTrace(); - } catch (NullPointerException e) { - e.printStackTrace(); - } + removeServerMBean(); } - // Add members + // remove members String[] members = getArrayProperty(props, "members"); for (String m : members) { - try { - addMemberMBean(m); - } catch (InstanceAlreadyExistsException e) { - e.printStackTrace(); - } catch (MBeanRegistrationException e) { - e.printStackTrace(); - } catch (NotCompliantMBeanException e) { - e.printStackTrace(); - } catch (MalformedObjectNameException e) { - e.printStackTrace(); - } catch (NullPointerException e) { - e.printStackTrace(); - } + removeMemberMBean(m); } - // Add regions + // remove regions String[] regions = getArrayProperty(props, "regions"); for (String reg : regions) { - try { - addRegionMBean(reg); - } catch (InstanceAlreadyExistsException e) { - e.printStackTrace(); - } catch (MBeanRegistrationException e) { - e.printStackTrace(); - } catch (NotCompliantMBeanException e) { - e.printStackTrace(); - } catch (MalformedObjectNameException e) { - e.printStackTrace(); - } catch (NullPointerException e) { - e.printStackTrace(); - } + removeRegionMBean(reg); } } private void addMemberMBean(String m) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException { - Member m1 = new Member(m); - mbs.registerMBean(m1, new ObjectName(Member.OBJECT_NAME + ",member=" + m)); + + mbs.registerMBean(new Member(m), new ObjectName(Member.OBJECT_NAME + ",member=" + m)); + } + + + private void removeMemberMBean(String m) + throws InstanceNotFoundException, + MBeanRegistrationException, MalformedObjectNameException { + mbs.unregisterMBean(new ObjectName(Member.OBJECT_NAME + ",member=" + m)); } private void addRegionMBean(String reg) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException, NullPointerException { Region regionObject = new Region(reg); + mbs.registerMBean(regionObject, new ObjectName(Region.OBJECT_NAME + ",name=/" + reg)); for (String member : regionObject.getMembers()) { @@ -209,11 +213,30 @@ public class Server { } } + private void removeRegionMBean(String reg) + throws InstanceNotFoundException, MBeanRegistrationException, MalformedObjectNameException, + NullPointerException { + Region regionObject = new Region(reg); + + mbs.unregisterMBean(new ObjectName(Region.OBJECT_NAME + ",name=/" + reg)); + + for (String member : regionObject.getMembers()) { + mbs.unregisterMBean(new ObjectName( + PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_REGION + regionObject.getFullPath() + + PulseConstants.OBJECT_NAME_REGION_ON_MEMBER_MEMBER + member)); + } + } + private void addServerMBean(String server) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException, NullPointerException { - ServerObject so = new ServerObject(server); - mbs.registerMBean(so, new ObjectName(ServerObject.OBJECT_NAME)); + mbs.registerMBean(new ServerObject(server), new ObjectName(ServerObject.OBJECT_NAME)); + } + + private void removeServerMBean() + throws InstanceNotFoundException, MBeanRegistrationException, + MalformedObjectNameException, NullPointerException { + mbs.unregisterMBean(new ObjectName(ServerObject.OBJECT_NAME)); } private String[] getArrayProperty(JMXProperties props, String propName) { @@ -221,15 +244,8 @@ public class Server { return propVal.split(" "); } - public static Server createServer(int jmxPort, String properties, String jsonAuthFile) { - Server s = null; - try { - s = new Server(jmxPort, properties, jsonAuthFile); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - - return s; + public static Server createServer(int jmxPort, String properties, String jsonAuthFile) + throws Exception { + return new Server(jmxPort, properties, jsonAuthFile); } } diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ServerRule.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ServerRule.java index 4ccfe25..dea5280 100644 --- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ServerRule.java +++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ServerRule.java @@ -17,6 +17,7 @@ package org.apache.geode.tools.pulse.tests.rules; import java.io.IOException; import java.io.InputStream; import java.util.Properties; +import java.util.concurrent.TimeUnit; import org.awaitility.Awaitility; import org.junit.rules.ExternalResource; @@ -34,75 +35,70 @@ public class ServerRule extends ExternalResource { private org.eclipse.jetty.server.Server jetty; private Server server; private String pulseURL; + private String jsonAuthFile; public ServerRule(String jsonAuthFile) { - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - String jmxPropertiesFile = classLoader.getResource("test.properties").getPath(); - - int jmxPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); - server = Server.createServer(jmxPort, jmxPropertiesFile, jsonAuthFile); - System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_HOST, LOCALHOST); - System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_PORT, Integer.toString(jmxPort)); - System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_EMBEDDED, String.valueOf(Boolean.TRUE)); - - int httpPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); - jetty = JettyHelper.initJetty(LOCALHOST, httpPort, new SSLConfig()); - JettyHelper.addWebApplication(jetty, PULSE_CONTEXT, getPulseWarPath(), null, null); - pulseURL = "http://" + LOCALHOST + ":" + httpPort + PULSE_CONTEXT; - System.out.println("Pulse started at " + pulseURL); + this.jsonAuthFile = jsonAuthFile; } public String getPulseURL() { return this.pulseURL; } - @Override protected void before() throws Throwable { - jetty.start(); - Awaitility.await().until(() -> jetty.isStarted()); + startServer(); + startJetty(); + Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> jetty.isStarted()); } @Override protected void after() { try { stopJetty(); - } finally { stopServer(); + } catch (Exception e) { + throw new RuntimeException(e); } } - private void stopServer() { - try { - if (server != null) { - server.stop(); - } - } catch (Exception e) { - throw new Error(e); - } + private void startServer() throws Exception { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + String jmxPropertiesFile = classLoader.getResource("test.properties").getPath(); + int jmxPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_PORT, Integer.toString(jmxPort)); + server = Server.createServer(jmxPort, jmxPropertiesFile, jsonAuthFile); + server.start(); } - private void stopJetty() { - try { - if (jetty != null) { - jetty.stop(); - jetty = null; - } - } catch (Exception e) { - throw new Error(e); - } + private void startJetty() throws Exception { + + System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_HOST, LOCALHOST); + System.setProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_EMBEDDED, + String.valueOf(Boolean.TRUE)); + + int httpPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); + jetty = JettyHelper.initJetty(LOCALHOST, httpPort, new SSLConfig()); + JettyHelper.addWebApplication(jetty, PULSE_CONTEXT, getPulseWarPath(), null, null); + pulseURL = "http://" + LOCALHOST + ":" + httpPort + PULSE_CONTEXT; + System.out.println("Pulse started at " + pulseURL); + jetty.start(); + } + + private void stopServer() throws Exception { + server.stop(); + } + + private void stopJetty() throws Exception { + jetty.stop(); } - private String getPulseWarPath() { - String warPath = null; + private String getPulseWarPath() throws IOException { + String warPath; ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream inputStream = classLoader.getResourceAsStream("GemFireVersion.properties"); Properties properties = new Properties(); - try { - properties.load(inputStream); - } catch (IOException e) { - throw new RuntimeException("Unable to open properties file", e); - } + properties.load(inputStream); String version = properties.getProperty("Product-Version"); warPath = "geode-pulse-" + version + ".war"; String propFilePath = classLoader.getResource("GemFireVersion.properties").getPath(); diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java index 63cc73f..272bcfd 100644 --- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java +++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java @@ -32,7 +32,7 @@ import org.openqa.selenium.support.ui.WebDriverWait; public class WebDriverRule extends ExternalResource { private WebDriver driver; - + static final int MAX_RETRIES = 10; private String pulseUrl; private String username; private String password; @@ -58,10 +58,25 @@ public class WebDriverRule extends ExternalResource { @Override public void before() throws Throwable { setUpWebDriver(); - driver.get(getPulseURL() + "login.html"); + + try { + driver.get(getPulseURL() + "login.html"); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("before: driver get exception " + e.getMessage()); + throw e; + } + if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) { - login(); + try { + login(); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("before: login exception " + e.getMessage()); + throw e; + } } + driver.navigate().refresh(); } @@ -79,12 +94,8 @@ public class WebDriverRule extends ExternalResource { driver.get(getPulseURL() + "clusterDetail.html"); WebElement userNameOnPulsePage = - (new WebDriverWait(driver, 30)).until(new ExpectedCondition<WebElement>() { - @Override - public WebElement apply(WebDriver d) { - return d.findElement(By.id("userName")); - } - }); + (new WebDriverWait(driver, 30, 1000)).until( + (ExpectedCondition<WebElement>) d -> d.findElement(By.id("userName"))); assertNotNull(userNameOnPulsePage); } @@ -95,22 +106,18 @@ public class WebDriverRule extends ExternalResource { options.addArguments("window-size=1200x600"); driver = new ChromeDriver(options); driver.manage().window().maximize(); - driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(300, TimeUnit.SECONDS); } - public WebElement waitForElementById(final String id) { + private WebElement waitForElementById(final String id) { return waitForElementById(id, 10); } - public WebElement waitForElementById(final String id, int timeoutInSeconds) { + private WebElement waitForElementById(final String id, int timeoutInSeconds) { WebElement element = - (new WebDriverWait(driver, timeoutInSeconds)).until(new ExpectedCondition<WebElement>() { - @Override - public WebElement apply(WebDriver d) { - return d.findElement(By.id(id)); - } - }); + (new WebDriverWait(driver, timeoutInSeconds, 1000)) + .until((ExpectedCondition<WebElement>) d -> d.findElement(By.id(id))); assertNotNull(element); return element; } diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseTestUtils.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseTestUtils.java index 2c17a56..3f8c985 100644 --- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseTestUtils.java +++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseTestUtils.java @@ -58,6 +58,7 @@ public class PulseTestUtils { } public static int maxWaitTime = 30; + public static int pollInterval = 1000; public static WebElement waitForElementWithId(String id) { return waitForElement(By.id(id)); @@ -409,27 +410,27 @@ public class PulseTestUtils { } public static void verifyElementPresentById(String id) { - WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, 500); + WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, pollInterval); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.id(id))); } public static void verifyElementPresentByLinkText(String lnkText) { - WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, 500); + WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, pollInterval); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText(lnkText))); } public static void verifyElementPresentByXpath(String xpath) { - WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, 500); + WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, pollInterval); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(xpath))); } public static void verifyTextPresrntById(String id, String text) { - WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, 500); + WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, pollInterval); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id(id), text)); } public static void verifyTextPresrntByXpath(String xpath, String text) { - WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, 500); + WebDriverWait wait = new WebDriverWait(getDriver(), maxWaitTime, pollInterval); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(xpath), text)); }