Java Code Examples for org.jboss.forge.furnace.Furnace#addContainerLifecycleListener()

The following examples show how to use org.jboss.forge.furnace.Furnace#addContainerLifecycleListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContainerLifecycleListenerTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testContainerStartup() throws Exception
{
   Furnace furnace = FurnaceFactory.getInstance();
   TestLifecycleListener listener = new TestLifecycleListener();
   ListenerRegistration<ContainerLifecycleListener> registration = furnace.addContainerLifecycleListener(listener);
   File temp = OperatingSystemUtils.createTempDir();
   temp.deleteOnExit();
   furnace.addRepository(AddonRepositoryMode.IMMUTABLE, temp);

   furnace.startAsync();
   waitUntilStarted(furnace);
   Assert.assertEquals(1, listener.beforeStartTimesCalled);
   Assert.assertEquals(1, listener.afterStartTimesCalled);
   registration.removeListener();
   furnace.stop();
}
 
Example 2
Source File: FurnaceSETest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAddonsLoadAPIClassesFromBootpathJAR() throws IOException, Exception
{
   Furnace furnace = FurnaceFactory.getInstance();

   furnace.addRepository(AddonRepositoryMode.MUTABLE, repodir1);

   AddonDependencyResolver resolver = new MavenAddonDependencyResolver();
   AddonManager manager = new AddonManagerImpl(furnace, resolver);

   AddonId no_dep = AddonId.from("test:no_dep", "1.0.0.Final");
   AddonId one_dep = AddonId.from("test:one_dep", "1.0.0.Final");

   manager.install(no_dep).perform();
   manager.install(one_dep).perform();

   ConfigurationScanListener listener = new ConfigurationScanListener();
   ListenerRegistration<ContainerLifecycleListener> registration = furnace.addContainerLifecycleListener(listener);

   furnace.startAsync();

   while (!listener.isConfigurationScanned())
      Thread.sleep(100);

   registration.removeListener();

   Addon projectsAddon = furnace.getAddonRegistry().getAddon(no_dep);
   Addons.waitUntilStarted(projectsAddon, 10, TimeUnit.SECONDS);

   ClassLoader addonClassLoader = projectsAddon.getClassLoader().loadClass(Addon.class.getName()).getClassLoader();
   ClassLoader appClassLoader = Addon.class.getClassLoader();
   Assert.assertNotEquals(appClassLoader, addonClassLoader);

   Assert.assertTrue(projectsAddon.getStatus().isStarted());
   furnace.stop();
}
 
Example 3
Source File: MultipleRepositoryViewTest.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testAddonsSharedIfSubgraphEquivalent() throws IOException, InterruptedException, TimeoutException
{
   Furnace furnace = FurnaceFactory.getInstance();
   AddonRepository left = furnace.addRepository(AddonRepositoryMode.MUTABLE, leftRepo);
   AddonRepository right = furnace.addRepository(AddonRepositoryMode.MUTABLE, rightRepo);

   AddonDependencyResolver resolver = new MavenAddonDependencyResolver();
   AddonManager manager = new AddonManagerImpl(furnace, resolver);

   AddonId no_dep = AddonId.from("test:no_dep", "1.0.0.Final");
   AddonId one_dep = AddonId.from("test:one_dep", "1.0.0.Final");
   AddonId one_dep_a = AddonId.from("test:one_dep_a", "1.0.0.Final");

   AddonId no_dep2 = AddonId.from("test:no_dep", "2.0.0.Final");

   Assert.assertFalse(left.isDeployed(one_dep_a));
   Assert.assertFalse(left.isDeployed(no_dep));
   Assert.assertFalse(left.isDeployed(no_dep2));
   Assert.assertFalse(left.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(one_dep_a));
   Assert.assertFalse(right.isDeployed(no_dep));
   Assert.assertFalse(right.isDeployed(no_dep2));
   Assert.assertFalse(right.isDeployed(one_dep));

   manager.install(no_dep, left).perform();
   manager.deploy(one_dep, left).perform();

   manager.deploy(one_dep_a, right).perform();
   manager.deploy(no_dep2, right).perform();

   Assert.assertFalse(left.isDeployed(one_dep_a));
   Assert.assertFalse(left.isDeployed(no_dep2));
   Assert.assertTrue(left.isDeployed(no_dep));
   Assert.assertTrue(left.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(no_dep));
   Assert.assertTrue(right.isDeployed(one_dep_a));
   Assert.assertTrue(right.isDeployed(no_dep2));

   ConfigurationScanListener listener = new ConfigurationScanListener();
   ListenerRegistration<ContainerLifecycleListener> registration = furnace.addContainerLifecycleListener(listener);

   furnace.startAsync();

   while (!listener.isConfigurationScanned())
      Thread.sleep(100);

   AddonRegistry registry = furnace.getAddonRegistry();
   Addons.waitUntilStarted(registry.getAddon(one_dep_a), 10, TimeUnit.SECONDS);
   AddonRegistry leftRegistry = furnace.getAddonRegistry(left);
   AddonRegistry rightRegistry = furnace.getAddonRegistry(right);

   Addon leftNoDep = leftRegistry.getAddon(no_dep);
   Addon rightNoDep = rightRegistry.getAddon(no_dep);
   Addon rootNoDep = registry.getAddon(no_dep);
   Assert.assertTrue(leftNoDep.getStatus().isStarted());
   Assert.assertFalse(rightNoDep.getStatus().isStarted()); // not deployed to this repository
   Assert.assertFalse(rootNoDep.getStatus().isStarted()); // there is a newer version

   Addon leftNoDep2 = leftRegistry.getAddon(no_dep2);
   Addon rightNoDep2 = rightRegistry.getAddon(no_dep2);
   Addon rootNoDep2 = registry.getAddon(no_dep2);
   Assert.assertFalse(leftNoDep2.getStatus().isStarted()); // not deployed to this repository
   Assert.assertTrue(rightNoDep2.getStatus().isStarted());
   Assert.assertTrue(rootNoDep2.getStatus().isStarted());

   Addon leftOneDep = leftRegistry.getAddon(one_dep);
   Addon rightOneDep = rightRegistry.getAddon(one_dep);
   Addon rootOneDep = registry.getAddon(one_dep);
   Assert.assertTrue(leftOneDep.getStatus().isStarted());
   Assert.assertFalse(rightOneDep.getStatus().isStarted()); // not deployed to this repository
   Assert.assertTrue(rootOneDep.getStatus().isStarted());

   Addon leftOneDepA = leftRegistry.getAddon(one_dep_a);
   Addon rightOneDepA = rightRegistry.getAddon(one_dep_a);
   Addon rootOneDepA = registry.getAddon(one_dep_a);
   Assert.assertFalse(leftOneDepA.getStatus().isStarted()); // not deployed to this repository
   Assert.assertTrue(rightOneDepA.getStatus().isStarted());
   Assert.assertTrue(rootOneDepA.getStatus().isStarted());

   registration.removeListener();

   furnace.stop();
}
 
Example 4
Source File: MultipleRepositoryViewTest.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testAddonsDuplicatedIfSubgraphDiffers() throws IOException, InterruptedException, TimeoutException
{
   Furnace furnace = FurnaceFactory.getInstance();
   AddonRepository left = furnace.addRepository(AddonRepositoryMode.MUTABLE, leftRepo);
   AddonRepository right = furnace.addRepository(AddonRepositoryMode.MUTABLE, rightRepo);
   AddonDependencyResolver resolver = new MavenAddonDependencyResolver();
   AddonManager manager = new AddonManagerImpl(furnace, resolver);

   AddonId no_dep = AddonId.from("test:no_dep", "1.0.0.Final");
   AddonId one_dep = AddonId.from("test:one_dep", "1.0.0.Final");
   AddonId one_dep_a = AddonId.from("test:one_dep_a", "1.0.0.Final");
   AddonId one_dep_lib = AddonId.from("test:one_dep_lib", "1.0.0.Final");

   AddonId one_dep_2 = AddonId.from("test:one_dep", "2.0.0.Final");

   Assert.assertFalse(left.isDeployed(one_dep_lib));
   Assert.assertFalse(left.isDeployed(one_dep_a));
   Assert.assertFalse(left.isDeployed(no_dep));
   Assert.assertFalse(left.isDeployed(one_dep));
   Assert.assertFalse(left.isDeployed(one_dep_2));
   Assert.assertFalse(right.isDeployed(one_dep_lib));
   Assert.assertFalse(right.isDeployed(one_dep_a));
   Assert.assertFalse(right.isDeployed(no_dep));
   Assert.assertFalse(right.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(one_dep_2));

   manager.install(no_dep, left).perform();
   manager.deploy(one_dep, left).perform();
   manager.deploy(one_dep_a, left).perform();
   manager.deploy(one_dep_lib, left).perform();

   manager.deploy(one_dep_2, right).perform();

   Assert.assertTrue(left.isDeployed(no_dep));
   Assert.assertTrue(left.isDeployed(one_dep));
   Assert.assertTrue(left.isDeployed(one_dep_a));
   Assert.assertTrue(left.isDeployed(one_dep_lib));
   Assert.assertFalse(left.isDeployed(one_dep_2));

   Assert.assertFalse(right.isDeployed(no_dep));
   Assert.assertFalse(right.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(one_dep_a));
   Assert.assertFalse(right.isDeployed(one_dep_lib));
   Assert.assertTrue(right.isDeployed(one_dep_2));

   ConfigurationScanListener listener = new ConfigurationScanListener();
   ListenerRegistration<ContainerLifecycleListener> registration = furnace.addContainerLifecycleListener(listener);

   furnace.startAsync();

   while (!listener.isConfigurationScanned())
      Thread.sleep(100);

   AddonRegistry registry = furnace.getAddonRegistry();
   Addons.waitUntilStarted(registry.getAddon(one_dep_a), 10, TimeUnit.SECONDS);
   AddonRegistry leftRegistry = furnace.getAddonRegistry(left);

   Addon addon = leftRegistry.getAddon(one_dep);
   Assert.assertNotNull(addon);

   registration.removeListener();

   furnace.stop();
}
 
Example 5
Source File: MultipleRepositoryTest.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testAddonsCanReferenceDependenciesInOtherRepositories() throws IOException, InterruptedException,
         TimeoutException
{
   Furnace furnace = FurnaceFactory.getInstance();
   AddonRepository left = furnace.addRepository(AddonRepositoryMode.MUTABLE, repodir1);
   AddonRepository right = furnace.addRepository(AddonRepositoryMode.MUTABLE, repodir2);

   AddonDependencyResolver resolver = new MavenAddonDependencyResolver();
   AddonManager manager = new AddonManagerImpl(furnace, resolver);

   AddonId no_dep = AddonId.from("test:no_dep", "1.0.0.Final");
   AddonId one_dep = AddonId.from("test:one_dep", "1.0.0.Final");
   AddonId one_dep_a = AddonId.from("test:one_dep_a", "1.0.0.Final");

   Assert.assertFalse(left.isDeployed(one_dep_a));
   Assert.assertFalse(left.isDeployed(no_dep));
   Assert.assertFalse(left.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(one_dep_a));
   Assert.assertFalse(right.isDeployed(no_dep));
   Assert.assertFalse(right.isDeployed(one_dep));

   manager.install(no_dep, left).perform();
   manager.deploy(one_dep, left).perform();
   manager.deploy(one_dep_a, right).perform();

   Assert.assertFalse(left.isDeployed(one_dep_a));
   Assert.assertFalse(right.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(no_dep));
   Assert.assertTrue(left.isDeployed(one_dep));
   Assert.assertTrue(left.isDeployed(one_dep));
   Assert.assertTrue(right.isDeployed(one_dep_a));

   ConfigurationScanListener listener = new ConfigurationScanListener();
   ListenerRegistration<ContainerLifecycleListener> registration = furnace.addContainerLifecycleListener(listener);

   furnace.startAsync();

   while (!listener.isConfigurationScanned())
      Thread.sleep(100);

   Addons.waitUntilStarted(furnace.getAddonRegistry().getAddon(one_dep_a), 10, TimeUnit.SECONDS);

   registration.removeListener();

   furnace.stop();
}
 
Example 6
Source File: MultipleRepositoryTest.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
@Test
   public void testAddonsDontFailIfDuplicatedInOtherRepositories() throws IOException, Exception
   {
      Furnace furnace = FurnaceFactory.getInstance();
      AddonRepository left = furnace.addRepository(AddonRepositoryMode.MUTABLE, repodir1);
      AddonRepository right = furnace.addRepository(AddonRepositoryMode.MUTABLE, repodir2);

      AddonDependencyResolver resolver = new MavenAddonDependencyResolver();
      AddonManager manager = new AddonManagerImpl(furnace, resolver);

      AddonId no_dep = AddonId.from("test:no_dep", "1.0.0.Final");
      AddonId one_dep = AddonId.from("test:one_dep", "1.0.0.Final");
      AddonId one_dep_a = AddonId.from("test:one_dep_a", "1.0.0.Final");

      Assert.assertFalse(left.isDeployed(one_dep_a));
      Assert.assertFalse(left.isDeployed(no_dep));
      Assert.assertFalse(left.isDeployed(one_dep));
      Assert.assertFalse(right.isDeployed(one_dep_a));
      Assert.assertFalse(right.isDeployed(no_dep));
      Assert.assertFalse(right.isDeployed(one_dep));

      manager.install(no_dep, left).perform();
      manager.deploy(one_dep, left).perform();
      manager.deploy(one_dep_a, left).perform();
      manager.deploy(one_dep_a, right).perform();

      Assert.assertFalse(right.isDeployed(no_dep));
      Assert.assertFalse(right.isDeployed(one_dep));
      Assert.assertTrue(left.isDeployed(one_dep_a));
      Assert.assertTrue(left.isDeployed(one_dep));
      Assert.assertTrue(left.isDeployed(one_dep_a));
      Assert.assertTrue(right.isDeployed(one_dep_a));

      ConfigurationScanListener listener = new ConfigurationScanListener();
      ListenerRegistration<ContainerLifecycleListener> registration = furnace.addContainerLifecycleListener(listener);

      furnace.startAsync();

      while (!listener.isConfigurationScanned())
         Thread.sleep(100);

      registration.removeListener();

      Addons.waitUntilStarted(furnace.getAddonRegistry().getAddon(one_dep_a), 10, TimeUnit.SECONDS);
      Addons.waitUntilStarted(furnace.getAddonRegistry().getAddon(no_dep), 10, TimeUnit.SECONDS);
      Addons.waitUntilStarted(furnace.getAddonRegistry().getAddon(one_dep), 10, TimeUnit.SECONDS);

      System.out.println("Getting instances.");
      //FIXME Mocked addons should contain these classes. Use reflection to avoid compile-time dependency ?
//      ExportedInstance<ConverterFactory> instance = furnace.getAddonRegistry()
//               .getExportedInstance(ConverterFactory.class);
//      ConverterFactory factory = instance.get();
//
//      factory.getConverter(File.class,
//               furnace.getAddonRegistry().getAddon(one_dep_a).getClassLoader()
//                        .loadClass("org.jboss.forge.addon.resource.DirectoryResource"));

      furnace.stop();
   }