@Test
  public void testVarAccess() {
    Configuration config = Configuration.instance();
    try {
      config.load();
    } catch (ConfigurationException e1) {
      e1.printStackTrace();
      fail();
    }
    BSFManager bsfManager = new BSFManager();
    BSFEngine engine = null;
    try {
      engine = bsfManager.loadScriptingEngine("BeanShell");
    } catch (BSFException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
    assertNotNull(engine);

    try {
      // ObjectRegistry registry = bsfManager.getObjectRegistry();
      // registry.register("mmm", new Integer(3));
      // engine.exec("source", 1, 1, "print( mmm );");
      engine.exec("source", 1, 1, "mmm = 1000;");
      engine.exec("source", 1, 1, "print( mmm );");
    } catch (BSFException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    engine.terminate();
  }
Beispiel #2
0
  /** Read the config file */
  private void setupConfig() {

    if (this.config == null)
      this.config =
          new NoCheatConfiguration(
              new File(NoCheatConfiguration.configFile),
              new File(NoCheatConfiguration.descriptionsFile));
    else
      this.config.config(
          new File(NoCheatConfiguration.configFile),
          new File(NoCheatConfiguration.descriptionsFile));

    config.setupFileLogger();

    try {
      this.chatLevel = config.getLogLevelValue("logging.logtochat");
      this.ircLevel = config.getLogLevelValue("logging.logtoirc");
      this.consoleLevel = config.getLogLevelValue("logging.logtoconsole");
      this.ircTag = config.getStringValue("logging.logtoirctag");
      this.useNewPermissionSystem = this.config.getBooleanValue("newpermsystem");
      this.showStartupMessages = this.config.getBooleanValue("showinfomessages");
    } catch (ConfigurationException e) {
      e.printStackTrace();
      this.setEnabled(false);
    }
  }
  public static void main(String[] args) {
    try {
      String oldConfigName;

      ClassLoader loader = Converter.class.getClassLoader();
      URL scpurl = loader.getResource(PREVIOUS_CONF_FILE);
      if (scpurl == null) scpurl = loader.getResource("storage-conf.xml");

      if (scpurl != null) oldConfigName = scpurl.getFile();
      else throw new ConfigurationException("Error finding previous configuration file.");
      System.out.println("Found previous configuration: " + oldConfigName);
      loadPreviousConfig(oldConfigName);

      System.out.println("Creating new configuration cassandra.yaml");
      dumpConfig("cassandra.yaml");
    } catch (IOException e) {
      System.out.println("Error creating new configuration file.");
      System.out.println(e.getMessage());
      e.printStackTrace();
    } catch (ConfigurationException e) {
      System.out.println("There was an error during config conversion.");
      System.out.println(e.getMessage());
      e.printStackTrace();
    }
  }
 @Test
 public void testLoad() {
   Configuration config = Configuration.instance();
   try {
     config.load();
   } catch (ConfigurationException e) {
     e.printStackTrace();
     fail();
   }
   assertTrue(BSFManager.isLanguageRegistered("BeanShell"));
 }
 @Test
 public void checkSomeProperties() {
   try {
     Configuration.instance().load();
   } catch (ConfigurationException e) {
     e.printStackTrace();
     fail();
   }
   assertEquals(-1, Configuration.instance().getHistoryDepth());
   assertEquals(1, Configuration.instance().getInteger("tangara.level"));
 }
 @Test
 public void testSysPropConf() {
   Configuration cfg = Configuration.instance();
   try {
     cfg.load();
   } catch (ConfigurationException e) {
     e.printStackTrace();
     fail();
   }
   assertNull(cfg.getProperty("name1"));
   System.setProperty(Configuration.CONF_SYS_P, "src/test/data/conf2.properties");
   Configuration cfg2 = Configuration.instance();
   try {
     cfg2.load();
   } catch (ConfigurationException e) {
     e.printStackTrace();
     fail();
   }
   assertEquals("value1", cfg2.getProperty("name1"));
   System.getProperties().remove("tangara.configuration");
 }
  @Test
  public void testEval() {
    Configuration config = Configuration.instance();
    try {
      config.load();
    } catch (ConfigurationException ex) {
      ex.printStackTrace();
      fail();
    }
    BSFManager bsfManager = new BSFManager();

    Integer i = new Integer(5);
    try {
      bsfManager.declareBean("i", i, Integer.class);
    } catch (BSFException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    BSFEngine engine = null;
    try {
      engine = bsfManager.loadScriptingEngine("BeanShell");
    } catch (BSFException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
    assertNotNull(engine);

    Integer j = new Integer(7);
    try {
      bsfManager.declareBean("j", j, Integer.class);
    } catch (BSFException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    try {
      engine.exec("source", 1, 1, "a=3;\nprint(a);");
      engine.exec("source", 1, 1, "a=a+1;\nprint(a);");
    } catch (BSFException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    try {
      engine.exec("source", 1, 1, "print(\"i=\"+i);");
      engine.exec("source", 1, 1, "j=j*10; print(\"j=\"+j);");
    } catch (BSFException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    // BSFDeclaredBean toto = new BSFDeclaredBean();
    // toto.beannew BSFDeclaredBean("i", i, Integer.class);
    ObjectRegistry registry = bsfManager.getObjectRegistry();
    Object jValue = registry.lookup("j");
    if (jValue != null) {
      System.out.println("j-value = " + jValue.toString());
    }
    registry.register("k", new Integer(1000));
    Object kValue = registry.lookup("k");
    assertNotNull(kValue);
    System.out.println("k=" + kValue.toString());
    try {
      engine.exec("source", 1, 1, "print(\"k=\"+k);");
    } catch (BSFException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
    try {
      bsfManager.declareBean("k", kValue, Integer.class);
    } catch (BSFException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
    try {
      engine.exec("source", 1, 1, "print(\"k=\"+k);");
    } catch (BSFException e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    engine.terminate();
  }
Beispiel #8
0
  public static void main(String[] args) throws CloneNotSupportedException {

    // Parameters for the configuration
    Algo algo = Algo.NRJ;
    Type type = Type.SECOND; // 2 methods if Algo.NRJ chosen

    int nbMachines = 10;
    int nbVms = 15;
    int sumOnOff = 50;
    int nbTry = 1;
    int maxOfExp = 1;
    // /////////////////////////////////////////////

    int indexNBofExp;
    int configPower;
    List<Long> times = new ArrayList<Long>();
    long t0, t1 = System.currentTimeMillis();

    for (indexNBofExp = 1; indexNBofExp <= maxOfExp; indexNBofExp++) {
      try {
        configLogger(nbVms, nbMachines, algo.toString());
      } catch (IOException e) {
        e.printStackTrace();
      }

      log2("\n\n#################################");
      log2("######### Experiments " + indexNBofExp + " #########");
      log2("#################################");

      PhysVirtConfiguration conf = new PhysVirtConfiguration();
      try {
        conf.makeConfiguration(algo.toString(), type.toString(), nbMachines, nbVms);
      } catch (ConfigurationException e1) {
        e1.printStackTrace();
      }

      for (int i = 0; i < nbTry; i++) {

        if (i != 0) {
          log2("\n\n#################################");
          log2("######### Loops " + (i + 1) + " ###############");
          log2("#################################");
        }

        switch (algo) {
          case NRJ:
            if (i == 0) {
              configPower = conf.initPower(type.toString());
              log2("\nSolution without constraint :\n ");
              log2(conf.print(false));
              log2(conf.print(true));
              log2(conf.show(false));
              log2("\n\nWelcome to the constraint world ...");
              log2("\n\n#################################");
              log2("######### Loops " + (i + 1) + " ###############");
              log2("#################################");
              if (SPREAD) {
                // initialize enemies
                for (vmsToSpread vts : vmsToSpread.values()) {
                  for (VM vm : conf.getVms()) {
                    if (vm.getName().equals(vts.name())) {
                      conf.addEnemies(vm);
                    }
                  }
                }
              }
            } else {
              configPower = conf.getComputePower();
            }
            conf.clearMachines();
            NRJConstraint nconstraint = new NRJConstraint(conf, SPREAD);
            t0 = System.currentTimeMillis();
            nconstraint.newModel(configPower, type.toString());
            t1 = System.currentTimeMillis();
            log2(conf.print(false));
            log2(conf.print(true));
            log2(conf.show(false));
            if (conf.isSatisfied()) {
              System.out.println("\nSatisfied");
            } else {
              System.err.println("\nNot satisfied");
            }
            times.add(t1 - t0);
            break;

          case PRIORITY:
            PriorityConstraint pconstraint = new PriorityConstraint(conf);
            if (i == 0) {
              log2("\nSolution without constraint :\n ");
              log2(conf.show(false));
              log2("\n\nWelcome to the constraint world ... ");
              log2("\n\n#################################");
              log2("######### Loops " + (i + 1) + " ###############");
              log2("#################################");
            }
            t0 = System.currentTimeMillis();
            pconstraint.newModel(sumOnOff);
            t1 = System.currentTimeMillis();
            log2(conf.show(true));
            times.add(t1 - t0);
            break;
          default:
            break;
        }

        log2("\nComputation time: " + times.get(times.size() - 1));
        // Solving times
        if (times.size() > 0) {
          log2("Solving times: " + times);
          long mean = 0;
          for (Long l : times) {
            mean += l;
          }
          log2("Mean: " + mean / times.size());
        }
      }
    }
  }