/** returns nice class name and method for the caller, going up the stack (filtered to remove invocation etc), * with 0 typically being the context where this method is called, 1 being its caller, etc */ public static String callerNiceClassAndMethod(int depth) { return niceClassAndMethod(callerStackElement(depth)); }
private ServerSocket connectToPort() throws Exception { ServerSocket result = new ServerSocket(0); LOG.info("Acquired port "+result+" for test "+JavaClassNames.niceClassAndMethod()); return result; }
@Test public void testCallerIsMe() { String result = JavaClassNames.niceClassAndMethod(); Assert.assertEquals(result, "JavaClassNamesCallerTest.testCallerIsMe"); }
@Test(groups={"Longevity","Acceptance"}) public void testLocationCreatedAndUnmanaged() throws Exception { doTestManyTimesAndAssertNoMemoryLeak(JavaClassNames.niceClassAndMethod(), new Runnable() { @Override public void run() { loc = newLoc(); managementContext.getLocationManager().unmanage(loc); } }); }
@Test public void testLocationCreatedAndUnmanaged() throws Exception { doTestManyTimesAndAssertNoMemoryLeak(JavaClassNames.niceClassAndMethod(), new Runnable() { @Override public void run() { loc = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); managementContext.getLocationManager().unmanage(loc); } }); }
@Test(groups={"Longevity","Acceptance"}) public void testAppCreatedStartedAndStopped() throws Exception { doTestStartAppThenThrowAway(JavaClassNames.niceClassAndMethod(), true); }
@Test public void testPortNotAvailableOnAnyNicWithReuseAddressWhenBoundToAnyNic() throws Exception { int port = findPort(); try (ServerSocket ss = new ServerSocket()) { ss.setReuseAddress(true); ss.bind(new InetSocketAddress(Networking.ANY_NIC, port)); log.info("acquired port on "+port+" for test "+JavaClassNames.niceClassAndMethod()); assertFalse(Networking.isPortAvailable(Networking.ANY_NIC, port, true), "port mistakenly reported as available"); // a specific NIC *will* be available //assertFalse(Networking.isPortAvailable(Networking.LOOPBACK, port, true), "port mistakenly reported as available"); } }
@Test public void testPortNotAvailableOnAnyNicOrLoopbackWithReuseAddressWhenBoundToLoopback() throws Exception { int port = findPort(); try (ServerSocket ss = new ServerSocket()) { ss.setReuseAddress(true); ss.bind(new InetSocketAddress(Networking.LOOPBACK, port)); log.info("acquired port on "+port+" for test "+JavaClassNames.niceClassAndMethod()); assertFalse(Networking.isPortAvailable(Networking.LOOPBACK, port, true), "port mistakenly reported as available"); assertFalse(Networking.isPortAvailable(Networking.ANY_NIC, port, true), "port mistakenly reported as available"); } }
@Test public void testPersistenceFailsIfIsFile() throws Exception { File tempF = File.createTempFile("test-"+JavaClassNames.niceClassAndMethod(), ".not_dir"); tempF.deleteOnExit(); String tempFileName = tempF.getAbsolutePath(); try { runRebindFails(PersistMode.AUTO, tempFileName, "must not be a file"); runRebindFails(PersistMode.REBIND, tempFileName, "must not be a file"); runRebindFails(PersistMode.CLEAN, tempFileName, "must not be a file"); } finally { new File(tempFileName).delete(); } }
@Test(groups={"Integration", "Broken"}) public void testSetsBrooklynPropertiesFromUri() throws Exception { File brooklynPropertiesSourceFile = File.createTempFile("brooklynnode-test", ".properties"); Files.write("abc=def", brooklynPropertiesSourceFile, Charsets.UTF_8); BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest() .configure(BrooklynNode.BROOKLYN_GLOBAL_PROPERTIES_REMOTE_PATH, pseudoBrooklynPropertiesFile.getAbsolutePath()) .configure(BrooklynNode.BROOKLYN_GLOBAL_PROPERTIES_URI, brooklynPropertiesSourceFile.toURI().toString())); app.start(locs); log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); assertEquals(Files.readLines(pseudoBrooklynPropertiesFile, Charsets.UTF_8), ImmutableList.of("abc=def")); }
@Test(groups={"Integration", "Broken"}) public void testSetsLocalBrooklynPropertiesFromContents() throws Exception { BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest() .configure(BrooklynNode.BROOKLYN_LOCAL_PROPERTIES_REMOTE_PATH, pseudoBrooklynPropertiesFile.getAbsolutePath()) .configure(BrooklynNode.BROOKLYN_LOCAL_PROPERTIES_CONTENTS, "abc=def")); app.start(locs); log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); assertEquals(Files.readLines(pseudoBrooklynPropertiesFile, Charsets.UTF_8), ImmutableList.of("abc=def")); }
@Test(groups={"Integration", "Broken"}) public void testSetsGlobalBrooklynPropertiesFromContents() throws Exception { BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest() .configure(BrooklynNode.BROOKLYN_GLOBAL_PROPERTIES_REMOTE_PATH, pseudoBrooklynPropertiesFile.getAbsolutePath()) .configure(BrooklynNode.BROOKLYN_GLOBAL_PROPERTIES_CONTENTS, "abc=def")); app.start(locs); log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); assertEquals(Files.readLines(pseudoBrooklynPropertiesFile, Charsets.UTF_8), ImmutableList.of("abc=def")); }
@Test(groups="Integration") // because takes approx 5 seconds public void testUpdateSeedsSlowAndRejoining() throws Exception { final int COUNT = 1; for (int i=0; i<COUNT; i++) { log.info("Test "+JavaClassNames.niceClassAndMethod()+", iteration "+(i+1)+" of "+COUNT); doTestUpdatesSeedsOnFailuresAndAdditions(false, true); tearDown(); setUp(); } }
@Test public void shouldAssertUrlUnreachableEventuallyWithFlags() throws Exception { String baseUrlOrig = baseUrl; LOG.info("testing "+JavaClassNames.niceClassAndMethod()+", server "+server.getUrl()); stopAfter(DELAY_FOR_SERVER_TO_SETTLE); startAfter(DELAY_FOR_SERVER_TO_SETTLE.add(DELAY_FOR_SERVER_TO_SETTLE).add(DELAY_FOR_SERVER_TO_SETTLE)); LOG.info(JavaClassNames.niceClassAndMethod()+" queued server changes"); HttpAsserts.assertUrlReachable(baseUrlOrig); HttpAsserts.assertUrlUnreachableEventually(ImmutableMap.of("timeout", "10s"), baseUrlOrig); }
@Test(groups={"Integration", "Broken"}) public void testStartsAppOnStartup() throws Exception { BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest() .configure(BrooklynNode.APP, BasicApplicationImpl.class.getName())); app.start(locs); log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); URI webConsoleUri = brooklynNode.getAttribute(BrooklynNode.WEB_CONSOLE_URI); waitForApps(webConsoleUri, 1); String apps = HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/applications"); List<String> appType = parseJsonList(apps, ImmutableList.of("spec", "type"), String.class); assertEquals(appType, ImmutableList.of(BasicApplication.class.getName())); }
@Test(groups={"Integration", "Broken"}) public void testSetsBrooklynWebConsolePort() throws Exception { BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest() .configure(BrooklynNode.HTTP_PORT, PortRanges.fromString("45000+"))); app.start(locs); log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); Integer httpPort = brooklynNode.getAttribute(BrooklynNode.HTTP_PORT); URI webConsoleUri = brooklynNode.getAttribute(BrooklynNode.WEB_CONSOLE_URI); assertTrue(httpPort >= 45000 && httpPort < 54100, "httpPort="+httpPort); assertEquals((Integer)webConsoleUri.getPort(), httpPort); HttpTestUtils.assertHttpStatusCodeEquals(webConsoleUri.toString(), 200, 401); }
@Test public void testLoadPolicySpecProgrammatically() { Factory loader = new BrooklynYamlTypeInstantiator.Factory(loader(), "test:"+JavaClassNames.niceClassAndMethod()); InstantiatorFromKey decoL = loader.from(MutableMap.of("some_type", ServiceRestarter.class.getName())).prefix("some"); Assert.assertTrue(decoL.getConfigMap().isEmpty()); Assert.assertEquals(decoL.getTypeName().get(), ServiceRestarter.class.getName()); Assert.assertEquals(decoL.getType(), ServiceRestarter.class); Object sl1 = decoL.newInstance(); Assert.assertTrue(sl1 instanceof ServiceRestarter); Policy sl2 = decoL.newInstance(Policy.class); Assert.assertTrue(sl2 instanceof ServiceRestarter); }
@Test(groups={"Integration", "Broken"}) public void testCanStartAndStop() throws Exception { BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest()); app.start(locs); log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); EntityAsserts.assertAttributeEqualsEventually(brooklynNode, BrooklynNode.SERVICE_UP, true); brooklynNode.stop(); EntityAsserts.assertAttributeEquals(brooklynNode, BrooklynNode.SERVICE_UP, false); }
@Test(groups = "WIP") public void testLoadPolicySpecWithFlag() { Factory loader = new BrooklynYamlTypeInstantiator.Factory(loader(), "test:"+JavaClassNames.niceClassAndMethod()); InstantiatorFromKey decoL = loader.from(MutableMap.of("some_type", ServiceRestarter.class.getName(), "failOnRecurringFailuresInThisDuration", Duration.seconds(42))).prefix("some"); Policy sl2 = decoL.newInstance(Policy.class); Assert.assertEquals(sl2.getConfig(ServiceRestarter.FAIL_ON_RECURRING_FAILURES_IN_THIS_DURATION).toSeconds(), 42); }
@Test public void testLoadPolicySpecWithBrooklynConfig() { Factory loader = new BrooklynYamlTypeInstantiator.Factory(loader(), "test:"+JavaClassNames.niceClassAndMethod()); InstantiatorFromKey decoL = loader.from(MutableMap.of("some_type", ServiceRestarter.class.getName(), "brooklyn.config", MutableMap.of("failOnRecurringFailuresInThisDuration", Duration.seconds(42)))).prefix("some"); Policy sl2 = decoL.newInstance(Policy.class); Assert.assertEquals(sl2.getConfig(ServiceRestarter.FAIL_ON_RECURRING_FAILURES_IN_THIS_DURATION).toSeconds(), 42); }