@Test public void testConfigFilterDeclared() throws Exception { MySubEntity entity = app.addChild(EntitySpec.create(MySubEntity.class)); Set<ConfigKey<?>> filteredKeys = entity.config().getInternalConfigMap().findKeysDeclared(ConfigPredicates.nameMatchesGlob("sup*")); Assert.assertTrue(filteredKeys.contains(MyBaseEntity.SUPER_KEY_1), "keys are: "+filteredKeys); Assert.assertTrue(filteredKeys.contains(MyBaseEntity.SUPER_KEY_2)); Assert.assertFalse(filteredKeys.contains(MySubEntity.SUB_KEY_2)); Asserts.assertSize(filteredKeys, 2); }
@Test public void testDeleteEmptyBundleRemovedFromPersistence() throws Exception { recreateOrigManagementContextWithOsgi(); String bom = Strings.lines( "brooklyn.catalog:", " itemType: entity", " items:", " - id: sample", " item:", " type: " + BasicEntity.class.getName()); addCatalogItems(bom); addCatalogItems(bom); rebind(); // should only contain one bundle / bundle.jar pair Asserts.assertSize(Arrays.asList( new File(mementoDir, "bundles").list() ), 2); }
@Test public void testConfigFilterPresent() throws Exception { MySubEntity entity = app.addChild(EntitySpec.create(MySubEntity.class)); entity.config().set(MyBaseEntity.SUPER_KEY_1, "s1"); entity.config().set(MySubEntity.SUB_KEY_2, "s2"); Set<ConfigKey<?>> filteredKeys = entity.config().getInternalConfigMap().findKeysPresent(ConfigPredicates.nameMatchesGlob("sup*")); Assert.assertTrue(filteredKeys.contains(MyBaseEntity.SUPER_KEY_1)); Assert.assertFalse(filteredKeys.contains(MySubEntity.SUB_KEY_2)); Assert.assertFalse(filteredKeys.contains(MyBaseEntity.SUPER_KEY_2)); Asserts.assertSize(filteredKeys, 1); }
@Test /** Tests catalog.bom format where service is defined alongside brooklyn.catalog, IE latter has no item/items */ public void testItemFromServicesSectionInCatalog() { addCatalogItems( "brooklyn.catalog:", " id: simple-test", " version: "+TEST_VERSION, "services:", "- type: org.apache.brooklyn.entity.stock.BasicEntity"); Iterable<RegisteredType> retrievedItems = mgmt().getTypeRegistry() .getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo("simple-test"))); Asserts.assertSize(retrievedItems, 1); Assert.assertEquals(Iterables.getOnlyElement(retrievedItems).getVersion(), TEST_VERSION); }
@Test /** Tests catalog.bom format where service is defined alongside brooklyn.catalog, IE latter has no item/items */ public void testYamlServiceForCatalog() { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); installWithoutCatalogBom(mgmt, OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL); Iterable<? extends CatalogItem<?, ?>> itemsInstalled = mgmt.getCatalog().addItems(Streams.readFullyStringAndClose(getClass().getResourceAsStream("test-app-service-blueprint.yaml"))); Asserts.assertSize(itemsInstalled, 1); CatalogItem<?, ?> itemInstalled = Iterables.getOnlyElement(itemsInstalled); Assert.assertEquals(itemInstalled.getSymbolicName(), "catalog-name"); Assert.assertEquals(itemInstalled.getVersion(), "0.9"); Iterable<RegisteredType> retrievedItems = mgmt.getTypeRegistry() .getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo("catalog-name"))); Asserts.assertSize(retrievedItems, 1); RegisteredType retrievedItem = Iterables.getOnlyElement(retrievedItems); Assert.assertEquals(retrievedItem.getVersion(), "0.9"); Collection<OsgiBundleWithUrl> bundles = retrievedItem.getLibraries(); Asserts.assertSize(bundles, 1); OsgiBundleWithUrl bundle = Iterables.getOnlyElement(bundles); Assert.assertEquals(bundle.getUrl(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL); Assert.assertEquals(bundle.getSuppliedVersionString(), "0.1.0"); }
@Test public void testLoadJustOneClassInOsgiWhiteList() throws Exception { String bundlePath = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH; String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; String classname = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY; TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), bundlePath); mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build(); Bundle bundle = installBundle(mgmt, bundleUrl); Class<?> clazz = bundle.loadClass(classname); Entity entity = createSimpleEntity(bundleUrl, clazz); String whiteList = bundle.getSymbolicName()+":"+bundle.getVersion(); System.setProperty(ClassLoaderUtils.WHITE_LIST_KEY, whiteList); ClassLoaderUtils cluEntity = new ClassLoaderUtils(getClass(), entity); BundledName resource = new BundledName(classname).toResource(); BundledName bn = new BundledName(resource.bundle, resource.version, "/" + resource.name); Asserts.assertSize(cluEntity.getResources(bn.toString()), 1); }
@Test public void testScanLegacyListedLibraries() { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH); TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH); addCatalogItems(bomForLegacySiblingLibraries()); RegisteredType hereItem = mgmt().getTypeRegistry().get("here-item"); assertEquals(hereItem.getVersion(), "2.0-test_java"); Asserts.assertSize(hereItem.getLibraries(), 2); assertEquals(hereItem.getContainingBundle(), "test-items:2.0-test_java"); RegisteredType item = mgmt().getTypeRegistry().get(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY); // versions and libraries _are_ inherited in this legacy mode assertEquals(item.getVersion(), "2.0-test_java"); Asserts.assertSize(hereItem.getLibraries(), 2); // and the containing bundle is recorded as the assertEquals(item.getContainingBundle(), "test-items"+":"+"2.0-test_java"); }
@Test public void testAddAnonymousBomTwiceDeletesOldEmptyOne() { Map<String, ManagedBundle> b1 = ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundles(); addCatalogItems(bomAnonymous()); Map<String, ManagedBundle> b2_new = MutableMap.copyOf( ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundles() ); for (String old: b1.keySet()) b2_new.remove(old); RegisteredType sample = mgmt().getTypeRegistry().get("sample"); Asserts.assertNotNull(sample); Asserts.assertSize(b2_new.values(), 1); addCatalogItems(bomAnonymous()); Map<String, ManagedBundle> b3 = MutableMap.copyOf( ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundles() ); Map<String, ManagedBundle> b3_new = MutableMap.copyOf(b3); for (String old: b1.keySet()) b3_new.remove(old); for (String old: b2_new.keySet()) b3_new.remove(old); Asserts.assertSize(b3_new.values(), 1); Asserts.assertFalse(b3_new.keySet().contains( Iterables.getOnlyElement(b2_new.keySet()) )); }
@Test public void testBrooklynManagedBundleInstall() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_MORE_ENTITIES_V1_PATH); OsgiBundleInstallationResult br = ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V1_URL) ).get(); Assert.assertEquals(br.getVersionedName().toString(), BROOKLYN_TEST_MORE_ENTITIES_SYMBOLIC_NAME_FULL+":"+"0.1.0"); // bundle installed Map<String, ManagedBundle> bundles = ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundles(); Asserts.assertSize(bundles.keySet(), 1); Assert.assertTrue(bundles.keySet().contains( br.getMetadata().getId() )); // types installed RegisteredType t = mgmt().getTypeRegistry().get(BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY); Assert.assertNotNull(t); Assert.assertEquals(t.getContainingBundle(), br.getVersionedName().toString()); // can deploy createAndStartApplication("services: [ { type: "+BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY+" } ]"); }
@Test // basic test that this approach to adding types works public void testAddTypes() throws Exception { String symbolicName = "my.catalog.app.id.load"; addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), BasicEntity.class.getName()); Iterable<RegisteredType> itemsInstalled = mgmt().getTypeRegistry().getMatching(RegisteredTypePredicates.containingBundle(new VersionedName(bundleName(), bundleVersion()))); Asserts.assertSize(itemsInstalled, 1); RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION); Asserts.assertEquals(item, Iterables.getOnlyElement(itemsInstalled), "Wrong item; installed: "+itemsInstalled); }
@Test public void testCatalogBomFromBundleWithManualManifest() throws Exception { bm.setDefaultClassForLoading(getClass()); File jf = bm.createJarFromClasspathDir("osgi/catalog-bundle-1"); jf = bm.copyRemoving(jf, MutableSet.of(JarFile.MANIFEST_NAME)); String customName = "catalog-bundle-1-manual-"+Identifiers.makeRandomId(4); jf = bm.copyAddingManifest(jf, MutableMap.of( "Manifest-Version", "2.0", "Bundle-SymbolicName", customName, "Bundle-Version", "0.0.0.SNAPSHOT")); Assert.assertTrue(bm.hasOsgiManifest(jf)); installBundle(jf); assertHasBasic1(); Entity basic1 = assertBasic1DeploysAndHasSensor(); RegisteredType item = mgmt().getTypeRegistry().get( basic1.getCatalogItemId() ); Collection<OsgiBundleWithUrl> libs = item.getLibraries(); Asserts.assertSize(libs, 1); Assert.assertEquals(Iterables.getOnlyElement(libs).getSymbolicName(), customName); }
assertEquals(newPolicy.getConfig(AutoScalerPolicy.MAX_SIZE_REACHED_SENSOR), MAX_SIZE_REACHED_SENSOR); assertEquals(newPolicy.getConfig(AutoScalerPolicy.MAX_REACHED_NOTIFICATION_DELAY), Duration.of(7, TimeUnit.MILLISECONDS)); Asserts.assertSize(newPolicy.getHighlights().keySet(), 1); assertEquals(newPolicy.getHighlights().get(AbstractEntityAdjunct.HIGHLIGHT_NAME_TRIGGERS).getDescription(), "Listening for "+METRIC_SENSOR.getName());
Asserts.assertSize(entity.config().findKeysDeclared(ConfigPredicates.nameMatchesRegex("p.*")), 0);