示例#1
0
  /*
   * Launches against the agent
   */
  public void testSimpleLauncher() throws Exception {
    Project project = workspace.getProject("p1");
    Run bndrun = new Run(workspace, project.getBase(), project.getFile("one.bndrun"));
    bndrun.setProperty("-runpath", "biz.aQute.remote.launcher");
    bndrun.setProperty("-runbundles", "bsn-1,bsn-2");
    bndrun.setProperty("-runremote", "test");

    final RemoteProjectLauncherPlugin pl =
        (RemoteProjectLauncherPlugin) bndrun.getProjectLauncher();
    pl.prepare();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger exitCode = new AtomicInteger(-1);

    List<? extends RunSession> sessions = pl.getRunSessions();
    assertEquals(1, sessions.size());

    final RunSession session = sessions.get(0);

    Thread t =
        new Thread("test-launch") {
          public void run() {
            try {
              exitCode.set(session.launch());
            } catch (Exception e) {
              e.printStackTrace();
            } finally {
              latch.countDown();
            }
          }
        };
    t.start();
    Thread.sleep(500);

    for (Bundle b : context.getBundles()) {
      System.out.println(b.getLocation());
    }
    assertEquals(4, context.getBundles().length);
    String p1 = t1.getAbsolutePath();
    System.out.println(p1);

    assertNotNull(context.getBundle(p1));
    assertNotNull(context.getBundle(t2.getAbsolutePath()));

    pl.cancel();
    latch.await();

    assertEquals(-3, exitCode.get());

    bndrun.close();
  }
 public static FrameworkDTO newFrameworkDTO(
     BundleContext systemBundleContext, Map<String, String> configuration) {
   FrameworkDTO dto = new FrameworkDTO();
   dto.properties = asProperties(configuration);
   if (systemBundleContext == null) {
     dto.bundles = newList(0);
     dto.services = newList(0);
     return dto;
   }
   Bundle[] bundles = systemBundleContext.getBundles();
   int size = bundles == null ? 0 : bundles.length;
   List<BundleDTO> bundleDTOs = newList(size);
   for (int i = 0; i < size; i++) {
     bundleDTOs.add(newBundleDTO(bundles[i]));
   }
   dto.bundles = bundleDTOs;
   try {
     ServiceReference<?>[] references = systemBundleContext.getAllServiceReferences(null, null);
     size = references == null ? 0 : references.length;
     List<ServiceReferenceDTO> refDTOs = newList(size);
     for (int i = 0; i < size; i++) {
       ServiceReferenceDTO serviceRefDTO = getServiceReferenceDTO(references[i]);
       if (serviceRefDTO != null) {
         refDTOs.add(serviceRefDTO);
       }
     }
     dto.services = refDTOs;
   } catch (InvalidSyntaxException e) {
     dto.services = newList(0);
   }
   return dto;
 }