public static String registerSpec(AbstractBrooklynObjectSpec<?, ?> spec) { String id = Identifiers.makeRandomId(10); REGISTERED_SPECS.put(id, spec); return id; }
@Override protected PersistenceObjectStore newPersistenceObjectStore() { return new JcloudsBlobStoreBasedObjectStore( BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4)); }
@Override public ConfigValuePair get() { String val = Identifiers.makeRandomId(10); return new ConfigValuePair(val, val); } };
@Test(groups = {"Integration"}) public void testConsecutiveBigStdinCommands() throws Exception { String bigstr = Identifiers.makeRandomId(100000); runExecManyCommands(ImmutableList.of("echo "+bigstr+" | wc -c"), "big-stdin", 10); }
/** Appends a standard format subpath sub-path to the path returned by {@link #resolve()}. * <p> * For example, this might write to: * <code>~/.brooklyn/brooklyn-persisted-state/backups/2014-11-13-1201-n0deId-promotion-sA1t */ public String resolveWithSubpathFor(ManagementContext managementContext, String label) { return resolveWithSubpath(Time.makeDateSimpleStampString()+"-"+managementContext.getManagementNodeId()+"-"+label+"-"+Identifiers.makeRandomId(4)); } @Override
@Test(groups="Live") public void testExecBatchFileMultiLine() throws Exception { String script = Joiner.on("\n").join( "@ECHO OFF", "echo first", "echo second", "EXIT /B 0"); String scriptPath = "C:\\myscript-"+Identifiers.makeRandomId(4)+".bat"; machine.copyTo(new ByteArrayInputStream(script.getBytes()), scriptPath); assertExecSucceeds(scriptPath, "first"+"\r\n"+"second", ""); }
@Test(groups="Live") public void testExecPsFileWithArg() throws Exception { String script = Joiner.on("\r\n").join( "Param(", " [string]$myarg", ")", "Write-Host got $myarg", "exit 0"); String scriptPath = "C:\\myscript-"+Identifiers.makeRandomId(4)+".ps1"; machine.copyTo(new ByteArrayInputStream(script.getBytes()), scriptPath); assertExecPsSucceeds("& "+scriptPath+" -myarg myval", "got myval", ""); }
@Test(groups="Live") public void testExecPsFilePs() throws Exception { String script = Joiner.on("\r\n").join( "Write-Host myline", "exit 0"); String scriptPath = "C:\\myscript-"+Identifiers.makeRandomId(4)+".ps1"; machine.copyTo(new ByteArrayInputStream(script.getBytes()), scriptPath); assertExecPsSucceeds("& "+scriptPath, "myline", ""); }
@Test(groups="Live") public void testExecPsCorruptExe() throws Exception { String exe = "garbage"; String exePath = "C:\\myscript-"+Identifiers.makeRandomId(4)+".exe"; machine.copyTo(new ByteArrayInputStream(exe.getBytes()), exePath); assertExecPsFails("& '"+exePath+"'"); }
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { mementoDir = Os.newTempDir(getClass()); File mementoDirParent = mementoDir.getParentFile(); mementoDirBackup = new File(mementoDirParent, mementoDir.getName()+"."+Identifiers.makeRandomId(4)+".bak"); origApp = null; newApp = null; newManagementContext = null; origManagementContext = createOrigManagementContext(); origApp = createApp(); LOG.info("Test "+getClass()+" persisting to "+mementoDir); }
@VisibleForTesting public static void addNamedLocationLocalhost(ManagementContext mgmt) { if (!mgmt.getConfig().getConfig(LocalhostLocationResolver.LOCALHOST_ENABLED)) { throw new IllegalStateException("Localhost is disabled."); } // ensure localhost is added (even on windows, it's just for testing) LocationDefinition l = mgmt.getLocationRegistry().getDefinedLocationByName("localhost"); if (l==null) mgmt.getLocationRegistry().updateDefinedLocation( BasicLocationRegistry.localhost(Identifiers.makeRandomId(8)) ); }
@Test(groups={"Integration"}) public void testLocalhost() throws Exception { doTestWithStore( newObjectStore(null, BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4)) ); }
/** * Exercise the {@link CassandraNode} using the Astyanax API. */ public void astyanaxTest() throws Exception { String keyspaceName = "BrooklynTests_"+Identifiers.makeRandomId(8); writeData(keyspaceName); readData(keyspaceName); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); localhost = app.getManagementContext().getLocationRegistry().getLocationManaged("localhost"); runRecord = Files.createTempFile("testVanillaSoftwareProcess-runRecord-"+Identifiers.makeRandomId(8), ".txt"); }
@Test(groups="Integration") // integration only because non-reusable OSGi takes ~200ms public void testOsgiPathCustom() { BrooklynProperties bp = BrooklynProperties.Factory.newEmpty(); String randomSeg = "osgi-test-"+Identifiers.makeRandomId(4); bp.put(BrooklynServerConfig.OSGI_CACHE_DIR, "${brooklyn.os.tmpdir}"+"/"+randomSeg+"/"+"${brooklyn.mgmt.node.id}"); mgmt = LocalManagementContextForTests.builder(true).enableOsgiNonReusable().useProperties(bp).build(); String path = BrooklynServerPaths.getOsgiCacheDir(mgmt).getAbsolutePath(); Os.deleteOnExitRecursivelyAndEmptyParentsUpTo(new File(path), new File(Os.tmp()+"/"+randomSeg)); Assert.assertTrue(path.startsWith(Os.tmp()), path); Assert.assertTrue(path.contains(mgmt.getManagementNodeId()), path); assertExistsThenIsCleaned(path); }
@Test(groups="Integration") // integration only because non-reusable OSGi takes ~200ms public void testOsgiPathCustomWithoutNodeIdNotCleaned() { BrooklynProperties bp = BrooklynProperties.Factory.newEmpty(); String randomSeg = "osgi-test-"+Identifiers.makeRandomId(4); bp.put(BrooklynServerConfig.OSGI_CACHE_DIR, "${brooklyn.os.tmpdir}"+"/"+randomSeg+"/"+"sample"); mgmt = LocalManagementContextForTests.builder(true).enableOsgiNonReusable().useProperties(bp).build(); String path = BrooklynServerPaths.getOsgiCacheDir(mgmt).getAbsolutePath(); Os.deleteOnExitRecursivelyAndEmptyParentsUpTo(new File(path), new File(Os.tmp()+"/"+randomSeg)); Assert.assertTrue(path.startsWith(Os.tmp()), path); Assert.assertFalse(path.contains(mgmt.getManagementNodeId()), path); assertExistsThenCorrectCleanedBehaviour(path, false); }
@Override public void onManagementStarted() { super.onManagementStarted(); enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag("z").tag(Identifiers.makeRandomId(8))); // all the enrichers above should not be added on rebind, but this one will be: enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag( Identifiers.makeRandomId(8) ).tag(Identifiers.makeRandomId(8))); } }
@Override @BeforeMethod public void setUp() throws Exception { store = new JcloudsBlobStoreBasedObjectStore( BlobStoreTest.PERSIST_TO_OBJECT_STORE_FOR_TEST_SPEC, BlobStoreTest.CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(4)); store.injectManagementContext(mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault())); store.prepareForSharedUse(PersistMode.CLEAN, HighAvailabilityMode.DISABLED); super.setUp(); }
@Override public void onManagementStarting() { super.onManagementStarted(); enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag("y").tag(Identifiers.makeRandomId(8))); } @Override
@Override protected void initEnrichers() { // don't add default ones enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag("x").tag(Identifiers.makeRandomId(8))); enrichers().add(EnricherSpec.create(MyEnricher.class)); } @Override