/** throws error, even if there is one (even if masked), else returns the object */ public T getWithError() { checkNoError(); return object; }
public void runRequiringTrue() { Stopwatch timer = Stopwatch.createStarted(); ReferenceWithError<Boolean> result = runKeepingError(); result.checkNoError(); if (!result.get()) { throw new IllegalStateException(description+" unsatisfied after "+Duration.of(timer)); } }
static void installJavaScanningMoreEntitiesV2(ManagementContext mgmt, Object context) throws FileNotFoundException { // scanning bundle functionality added in 0.12.0, relatively new compared to non-osgi scanning TestResourceUnavailableException.throwIfResourceUnavailable(context.getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH); TestResourceUnavailableException.throwIfResourceUnavailable(context.getClass(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH); CampYamlLiteTest.installWithoutCatalogBom(mgmt, OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH); BundleMaker bm = new BundleMaker(mgmt); File f = Os.newTempFile(context.getClass(), "jar"); Streams.copy(ResourceUtils.create(context).getResourceFromUrl(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH), new FileOutputStream(f)); f = bm.copyRemoving(f, MutableSet.of("catalog.bom")); f = bm.copyAdding(f, MutableMap.of(new ZipEntry("catalog.bom"), new ByteArrayInputStream( Strings.lines( "brooklyn.catalog:", " scanJavaAnnotations: true").getBytes() ) )); ((ManagementContextInternal)mgmt).getOsgiManager().get().install(new FileInputStream(f)).checkNoError(); }
public static void addCatalogItemsAsOsgiInUsualWay(ManagementContext mgmt, String catalogYaml, VersionedName bundleName, boolean force) { try { BundleMaker bundleMaker = new BundleMaker(mgmt); File bf = bundleMaker.createTempZip("test", MutableMap.of( new ZipEntry(BasicBrooklynCatalog.CATALOG_BOM), new ByteArrayInputStream(catalogYaml.getBytes()))); if (bundleName!=null) { bf = bundleMaker.copyAddingManifest(bf, MutableMap.of( "Manifest-Version", "2.0", Constants.BUNDLE_SYMBOLICNAME, bundleName.getSymbolicName(), Constants.BUNDLE_VERSION, bundleName.getOsgiVersion().toString())); } ReferenceWithError<OsgiBundleInstallationResult> b = ((ManagementContextInternal)mgmt).getOsgiManager().get().install( new FileInputStream(bf) ); b.checkNoError(); } catch (Exception e) { throw Exceptions.propagate(e); } }
protected RegisteredType installWrappedMoreEntity() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_OSGI_ENTITIES_PATH); TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_MORE_ENTITIES_V2_PATH); ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_OSGI_ENTITIES_URL) ).checkNoError(); ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_URL) ).get(); addCatalogItems( "brooklyn.catalog:", " id: wrapped-more-entity", " version: 1.0", " item:", " services:", " - type: " + BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY); RegisteredType ci = Preconditions.checkNotNull( mgmt().getTypeRegistry().get("wrapped-more-entity") ); return ci; }
@Test public void testClusterWithEntitySpecFromOsgi() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_OSGI_ENTITIES_PATH); TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_MORE_ENTITIES_V2_PATH); // install dependencies ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_OSGI_ENTITIES_URL) ).checkNoError(); ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_URL) ).get(); RegisteredType ci = Preconditions.checkNotNull( mgmt().getTypeRegistry().get(BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY) ); EntitySpec<DynamicCluster> clusterSpec = EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.INITIAL_SIZE, 1) .configure(DynamicCluster.MEMBER_SPEC, origManagementContext.getTypeRegistry().createSpec(ci, null, EntitySpec.class)); final Entity app = mgmt().getEntityManager().createEntity(EntitySpec.create(BasicApplication.class).child(clusterSpec)); app.invoke(Startable.START, MutableMap.of()).get(); rebind(); }
new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_OSGI_ENTITIES_URL) ).checkNoError();