@Before
  public void before() throws ProActiveException, URISyntaxException {
    remoteObjectDeployer = new NamingServiceDeployer();

    final String[] urls = remoteObjectDeployer.getNamingServiceURLs();
    // PROACTIVE-1303 : we replace the default url to test that it can switch to the second
    urls[0] = CentralPAPropertyRepository.PA_COMMUNICATION_PROTOCOL.getValue() + "://foo";
    stub = NamingService.createNamingServiceStub(urls);
  }
Beispiel #2
0
    private void configure(final long appId, final String namingServiceURL)
        throws FileSystemException, URISyntaxException, ProActiveException, ConfigurationException {

      // create naming service stub with URL and decorate it with local cache
      // use local variables so GC can collect them if something fails
      final NamingService namingService;
      try {
        namingService = NamingService.createNamingServiceStub(namingServiceURL);
      } catch (ProActiveException x) {
        logger.error("Could not access Naming Service", x);
        throw x;
      } catch (URISyntaxException x) {
        logger.error("Wrong Naming Service URI", x);
        throw x;
      }
      final CachingSpacesDirectory cachingDir = new CachingSpacesDirectory(namingService);

      // create scratch data space for this application and register it
      if (nodeScratchSpace != null) {
        applicationScratchSpace = nodeScratchSpace.initForApplication(appId);
        final SpaceInstanceInfo scratchInfo = applicationScratchSpace.getSpaceInstanceInfo();

        boolean registered = false;
        try {
          cachingDir.register(scratchInfo);
          registered = true;
          logger.debug("Scratch space for application registered");
        } catch (SpaceAlreadyRegisteredException e) {
          logger.error("Could not register application scratch space to Naming Service", e);
          throw e;
        } catch (WrongApplicationIdException e) {
          logger.error("Could not register application scratch space to Naming Service", e);
          throw e;
        } finally {
          if (!registered) {
            nodeScratchSpace.close();
          }
        }
      }
      // no exception can be thrown since now
      cachingDirectory = cachingDir;

      // create VFSSpacesMountManagerImpl
      spacesMountManager = new VFSSpacesMountManagerImpl(cachingDirectory);

      // create implementation object connected to the application's
      // configuration
      impl =
          new DataSpacesImpl(appId, spacesMountManager, cachingDirectory, applicationScratchSpace);
    }
 private void assertIsSpaceUnregistered(SpaceInstanceInfo expected) {
   assertNull(stub.lookupOne(expected.getMountingPoint()));
 }
 private void assertIsSpaceRegistered(SpaceInstanceInfo expected) {
   SpaceInstanceInfo actual = stub.lookupOne(expected.getMountingPoint());
   assertEquals(actual.getMountingPoint(), expected.getMountingPoint());
 }
  @Test
  public void test()
      throws ApplicationAlreadyRegisteredException, WrongApplicationIdException,
          SpaceAlreadyRegisteredException, IllegalArgumentException {

    Set<SpaceInstanceInfo> spaces = new HashSet<SpaceInstanceInfo>();
    Set<Long> appsRegistered;

    spaces.add(spaceInstanceInput1);
    spaces.add(spaceInstanceInput2);
    spaces.add(spaceInstanceOutput1);
    spaces.add(spaceInstanceOutput2);

    assertFalse(stub.isApplicationIdRegistered(MAIN_APPID));
    // TEST REGISTER APP
    logger.info("Test register application");
    stub.registerApplication(MAIN_APPID, spaces);

    // check if everything has been registered
    logger.info("Checking that application has been registered");
    assertTrue(stub.isApplicationIdRegistered(MAIN_APPID));
    appsRegistered = stub.getRegisteredApplications();
    appsRegistered.contains(MAIN_APPID);

    // TEST LOOKUP FIRST
    logger.info("Test Lookup First");
    assertIsSpaceRegistered(spaceInstanceInput1);
    assertIsSpaceRegistered(spaceInstanceInput2);
    assertIsSpaceRegistered(spaceInstanceOutput1);
    assertIsSpaceRegistered(spaceInstanceOutput2);

    // TEST LOOKUP ALL
    logger.info("Test Lookup All");
    final DataSpacesURI query = DataSpacesURI.createURI(MAIN_APPID);
    final Set<SpaceInstanceInfo> actual = stub.lookupMany(query);
    assertEquals(spaces, actual);

    // TEST UNREGISTER
    logger.info("Test unregister");
    assertTrue(stub.unregister(spaceInstanceInput1.getMountingPoint()));
    assertTrue(stub.unregister(spaceInstanceOutput1.getMountingPoint()));

    // TEST LOOKUP FIRST WITH NULL ANSWER
    logger.info("Test looup first with null answer");
    assertIsSpaceUnregistered(spaceInstanceInput1);
    assertIsSpaceUnregistered(spaceInstanceOutput1);

    // TEST REGISTER
    logger.info("Test register");
    stub.register(spaceInstanceInput1);
    stub.register(spaceInstanceOutput1);

    // TEST EXCEPTION WHEN SPACE ALREADY REGISTERED
    logger.info("Test Exception when space already registered");
    try {
      stub.register(spaceInstanceInput1);
      fail("Exception expected");
    } catch (SpaceAlreadyRegisteredException e) {
    } catch (Exception e) {
      fail("Expected exception of different type");
    }

    // TEST EXCEPTION WHEN APP NOT REGISTERED
    logger.info("Test Exception when app not registered");
    try {
      stub.register(spaceInstanceInput1b);
      fail("Exception expected");
    } catch (WrongApplicationIdException e) {
    } catch (Exception e) {
      fail("Expected exception of different type");
    }

    // TEST EXCEPTION WHEN APP ALREADY REGISTERED
    logger.info("Test Exception when app already registered");
    try {
      stub.registerApplication(MAIN_APPID, null);
      fail("Exception expected");
    } catch (ApplicationAlreadyRegisteredException e) {
    } catch (Exception e) {
      fail("Expected exception of different type");
    }

    // TEST UNREGISTER APP
    logger.info("Test unregister");
    stub.unregisterApplication(MAIN_APPID);
  }