Package fr.imag.adele.apam

Examples of fr.imag.adele.apam.Instance


    public void SingletonNotSharedInstance_tc015() {

  Implementation impl = waitForImplByName(null,
    "HouseMeterSingletonNotShared");

  Instance inst1 = impl.createInstance(null,
    new HashMap<String, String>());
  Instance inst2 = null;

  try {
      inst2 = impl.createInstance(null, new HashMap<String, String>());
  } catch (Exception e) {
      // Nothing to do
View Full Code Here


      rootComposite = (Composite) root.getInst();
  }

  impl.createInstance(null, null);

  Instance inst1 = CST.apamResolver.resolveImpl(rootComposite, impl,
    new HashSet<String>(), new ArrayList<String>());
  Instance inst2 = CST.apamResolver.resolveImpl(rootComposite, impl,
    new HashSet<String>(), new ArrayList<String>());
  Instance inst3 = CST.apamResolver.resolveImpl(rootComposite, impl,
    new HashSet<String>(), new ArrayList<String>());

  final String message = "In case of a singleton and shared instance, all instances should be the same";

  Assert.assertTrue(message, inst1 == inst2);
View Full Code Here

    /*
     * Create and register the object in the APAM state model
     */
   
    Instance instance = null;
    try {
      instance = instantiate(composite, initialProperties);
      ((InstanceImpl) instance).register(initialProperties);
      setInstantiateFails(false);
      return instance;
    } catch (InvalidConfiguration configurationError) {

      /*
       * TODO this should be done in method register, we should try to have some form
       * of atomic registration that includes registration and addition in the broker
       */
      if (instance != null) {
        if (CST.componentBroker.getComponent(instance.getName()) != null) {
          /*
           * If creation failed after broker registration, undo registration
           */
          ((ComponentBrokerImpl) CST.componentBroker).disappearedComponent(instance);
        }
View Full Code Here

    @Test
    public void ConstraintsCheckingInstanceFilteringBySetProperty_tc011()
      throws InvalidSyntaxException {

  Implementation samsungImpl = waitForImplByName(null, "SamsungSwitch");
  final Instance samsungInst = samsungImpl.createInstance(null, null);

  Implementation lgImpl = waitForImplByName(null, "LgSwitch");
  final Instance lgInst = lgImpl.createInstance(null, null);

  Implementation siemensImpl = waitForImplByName(null, "SiemensSwitch");
  final Instance siemensInst = siemensImpl.createInstance(null, null);

  Implementation boschImpl = waitForImplByName(null, "BoschSwitch");
  final Instance boschInst = boschImpl.createInstance(null, null);

  Implementation philipsImpl = waitForImplByName(null, "philipsSwitch");
  final Instance philipsInst = philipsImpl.createInstance(null, null);

  samsungInst.setProperty("currentVoltage", "95");
  lgInst.setProperty("currentVoltage", "100");
  siemensInst.setProperty("currentVoltage", "105");
  boschInst.setProperty("currentVoltage", "110");
  philipsInst.setProperty("currentVoltage", "117");

  apam.waitForIt(Constants.CONST_WAIT_TIME);

  Set<Instance> validInstances = new HashSet<Instance>() {
      {
    add(siemensInst);
    add(lgInst);
    add(boschInst);
    add(samsungInst);
      }
  };

  Implementation s1Impl = waitForImplByName(null, "fr.imag.adele.apam.pax.test.impl.S1Impl");

  Instance s1Inst = s1Impl.createInstance(null, null);
  S1Impl s1 = (S1Impl) s1Inst.getServiceObject();

  // auxListInstanceReferencedBy("#################",s1.getEletronicInstancesConstraintsInstance());
  auxListInstances("-------Available instances before using the list-------");

  System.out.println("Size of the injected list:"  + s1.getEletronicInstancesConstraintsInstance().size());

  for (Eletronic e : s1.getEletronicInstancesConstraintsInstance()) {
      Instance p = CST.componentBroker.getInstService(e);
      System.out.println("---- Voltage:"
        + p.getProperty("currentVoltage") + " / Name:"
        + p.getName());

      boolean found = false;

      for (Instance l : validInstances) {
    if (l.getName().equals(p.getName())) {
        found = true;
        break;
    }
      }

      // Check if all valid instances were injected
      Assert.assertTrue(
        String.format(
          "Instance %s (currentVoltage:%s) was injected even if its does not obey the constraint (currentVoltage <= 110)",
          p.getName(), p.getProperty("currentVoltage")), p
          .match("(currentVoltage <= 110)"));
      Assert.assertTrue(
        String.format(
          "Instance %s (currentVoltage:%s) was not found in the list of valid instances for the constraint (currentVoltage <= 110)",
          p.getName(), p.getProperty("currentVoltage")),
        found);

  }

  auxListInstances("-------Available instances after using the list-------");
View Full Code Here

    Assert.assertNotNull(
        "Obrman-Test-S3Impl cannot be resolved (cannot be found using obrman)",
        implementation);

    Instance instance = implementation.createInstance(null,
        Collections.<String, String> emptyMap());

    Assert.assertNotNull("Instance of Obrman-Test-S3Impl is null", instance);
    Bundle bundle = implementation.getApformComponent().getBundle();
View Full Code Here

    waitForApam();

    Implementation implementation = waitForImplByName(null,
        "S07-implementation-14ter");

    Instance instance = implementation.createInstance(null,
        Collections.<String, String> emptyMap());

    // Test should success on external bundle resolution
    auxListInstances();
    org.junit.Assert
        .assertFalse(
            "No exception should be raised as the dependency can be resolved externally",
            testResolutionException(instance, 3));
    Assert.assertEquals("Only one relation should have been created : ", 1,
        instance.getRawLinks().size());

  }
View Full Code Here

      for (PropertyDefinition definition : primitive.getPropertyDefinitions()) {
       
        if (definition.getField() != null && definition.getField().equals(fieldName) ) {
         
          String property    = definition.getName();
          Instance instance   = getInstanceManager().getApamComponent();
          /*
           * For primitive property fields, always return the APAM value that is already of the
           * correct type and is always synchronized
           */
          if (! definition.isSet())
            return instance.getPropertyObject(property);
         
          /*
           * For multi-valued property fields, convert the APAM value to a collection that can
           * be injected into the field, and that track modifications
           */
          if (definition.isSet() ) {

            @SuppressWarnings("unchecked")
          Set<String> newValue     = (Set<String>) instance.getPropertyObject(property);
              BoundSet<?> injectedValue  = null;
             
            if (definition.getBaseType().equals("int") && newValue != null) {
             
              injectedValue = new BoundSet<Integer>(newValue,instance,definition) {
View Full Code Here

      for (PropertyDefinition definition : primitive.getPropertyDefinitions()) {
       
        if (definition.getField() != null && definition.getField().equals(fieldName)) {
         
          String property    = definition.getName();
          Instance instance   = getInstanceManager().getApamComponent();

          /*
           * If the field has been modified, and the injection type is not EXTERNAL update the Apam value
           */
              if (newValue != null && newValue instanceof BoundSet<?>)
                newValue = ((BoundSet<?>) newValue).unwrap();

              Object currentValue = instance.getPropertyObject(property);

              if (newValue != null && currentValue != null && currentValue.equals(newValue))
                continue;

              if (newValue == null && currentValue == null)
View Full Code Here

  public void testReaction () {
    System.out.println("=========== start testReaction test");

    System.out.println("creating 2 instances");
    Implementation implS1 = CST.apamResolver.findImplByName(null,"S1ImplEmpty");
    Instance s1 = implS1.createInstance(null, null);
    Instance s2 = implS1.createInstance(null, null);

    Instance test = CST.componentBroker.getInstService(testReaction) ;
    System.out.println("connected to " + test.getName());
    if (test == s1)
      s2.setProperty("debit", 100) ;
    else
      s1.setProperty("debit", 100) ;

    thisInstance.setProperty("need", 20) ;
    test = CST.componentBroker.getInstService(testReaction) ;
    System.out.println("connected to " + test.getName());

    //      =========== start testReaction test
    //          creating 2 instances
    //          connected to S1ImplEmpty-0
    //          connected to S1ImplEmpty-1
View Full Code Here

    implS1.createInstance(null, null);
    nbInst++ ;
    implS1.createInstance(null, null);
    nbInst++ ;

    Instance test = null ;

    String s ;
    Link l ;
    for (int k = 0; k < 10; k++) {
      System.out.println("creating 1000 instances");
      for (int i = 0; i < 100; i++) {
        test = implS1.createInstance(null, null);
        nbInst++ ;
      }
      test.setProperty("debit"2000) ;
      for (int j = 0; j < 10; j++) {

        deb = System.nanoTime();
        for (int i = 0; i < nb; i++) {
          simpleDep.getName();
          simpleDep = null ;
//          l = thisInstance.getLink("testSimple") ;
//          l.reevaluate(true, true) ;
        }
        fin = System.nanoTime();
        duree = (fin - deb) ;
        System.out.println("Nombre d'instances " + nbInst + " : duree de " + nb + " resolution sans contrainte : " + duree/1000000 + " milli secondes");   

        //Contrainte
        deb = System.nanoTime();
        for (int i = 0; i < nb; i++) {
          constraintDep.getName();
          constraintDep = null ;
//          l = thisInstance.getLink("testPerf") ;
//          l.reevaluate(true, true) ;
        }
        fin = System.nanoTime();
        duree = (fin - deb - overHead) ;
        System.out.println("Nombre d'instances " + nbInst + " : duree de " + nb + " resolution avec contrainte : " + duree/1000000 + " milli secondes");   

        //predference
        deb = System.nanoTime();
        for (int i = 0; i < nb; i++) {
          preferenceDep.getName() ; //resolve if pointer is null
          preferenceDep = null;    //remove the link
//          l = thisInstance.getLink("testPerfPrefere") ;
//          l.reevaluate(true, true) ;
        }
        fin = System.nanoTime();
        duree = (fin - deb - overHead) ;
        System.out.println("Nombre d'instances " + nbInst + " : duree de " + nb + " resolution avec preference : " + duree/1000000 + " milli secondes");   
     

        deb = System.nanoTime();
        //      System.out.println(testSimple.getName());
        for (int i = 0; i < nb; i++) {
          test = CST.componentBroker.getInstService(simpleDep) ;
          test.setProperty("debit", 10) ;
          test.setProperty("debit", 20) ;
          s = simpleDep.getName() ;
          //        System.out.println(s);
        }
        fin = System.nanoTime();
        overHead = (fin - deb) ;
        System.out.println("Nombre d'instances " + nbInst + " : duree de " + nb + " overhead : " + overHead/1000000 + " milli secondes");

        deb = System.nanoTime();
        //      System.out.println(testPerf.getName());

                // PAxizer ce test (le for) : Fait !
        for (int i = 0; i < nb; i++) {
          test = CST.componentBroker.getInstService(simpleDep) ;
          test.setProperty("debit", 2) ;
          s= simpleDep.getName() ;
          test.setProperty("debit", 10) ;
          //System.out.println(s);
        }
        fin = System.nanoTime();
        duree = (fin - deb- overHead) ;
        System.out.println("Nombre d'instances " + nbInst +  " : duree de " + nb + " appels avec contrainte et changement de dep : " + duree/1000000 + " milli secondes");
View Full Code Here

TOP

Related Classes of fr.imag.adele.apam.Instance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.