public void testMissingSetting() throws InterruptedException {
    String collector = randomAsciiOfLength(5);
    Set<AbstractMap.SimpleEntry<String, String>> entries = new HashSet<>();
    entries.add(
        new AbstractMap.SimpleEntry<>(
            "monitor.jvm.gc.collector." + collector + ".warn", randomPositiveTimeValue()));
    entries.add(
        new AbstractMap.SimpleEntry<>(
            "monitor.jvm.gc.collector." + collector + ".info", randomPositiveTimeValue()));
    entries.add(
        new AbstractMap.SimpleEntry<>(
            "monitor.jvm.gc.collector." + collector + ".debug", randomPositiveTimeValue()));
    Settings.Builder builder = Settings.builder();

    // drop a random setting or two
    for (@SuppressWarnings("unchecked")
    AbstractMap.SimpleEntry<String, String> entry :
        randomSubsetOf(randomIntBetween(1, 2), entries.toArray(new AbstractMap.SimpleEntry[0]))) {
      builder.put(entry.getKey(), entry.getValue());
    }

    // we should get an exception that a setting is missing
    execute(
        builder.build(),
        (command, interval) -> null,
        t -> {
          assertThat(t, instanceOf(IllegalArgumentException.class));
          assertThat(
              t.getMessage(),
              containsString(
                  "missing gc_threshold for [monitor.jvm.gc.collector." + collector + "."));
        },
        true,
        null);
  }
 protected static Map<String, String> toParameters(
     AbstractMap.SimpleEntry<String, String>... entries) {
   Map<String, String> map = new HashMap<>();
   for (AbstractMap.SimpleEntry<String, String> entry : entries) {
     map.put(entry.getKey(), entry.getValue());
   }
   return map;
 }
예제 #3
0
 private Integer findValue(int key, AbstractMap.SimpleEntry<Integer, Integer>[] values) {
   for (AbstractMap.SimpleEntry<Integer, Integer> value : values) {
     if (value.getKey().equals(key)) {
       return value.getValue();
     }
   }
   return null;
 }
예제 #4
0
  private void testContainsValue(Config config) throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);

    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);

    final ReplicatedMap<Integer, Integer> map1 = instance1.getReplicatedMap("default");
    final ReplicatedMap<Integer, Integer> map2 = instance2.getReplicatedMap("default");

    final AbstractMap.SimpleEntry<Integer, Integer>[] testValues = buildTestValues();

    WatchedOperationExecutor executor = new WatchedOperationExecutor();
    executor.execute(
        new Runnable() {
          @Override
          public void run() {
            int half = testValues.length / 2;
            for (int i = 0; i < testValues.length; i++) {
              final ReplicatedMap<Integer, Integer> map = i < half ? map1 : map2;
              final AbstractMap.SimpleEntry<Integer, Integer> entry = testValues[i];
              map.put(entry.getKey(), entry.getValue());
            }
          }
        },
        60,
        EntryEventType.ADDED,
        testValues.length,
        1,
        map1,
        map2);

    int map2Contains = 0;
    for (AbstractMap.SimpleEntry<Integer, Integer> testValue : testValues) {
      if (map2.containsValue(testValue.getValue())) {
        map2Contains++;
      }
    }
    int map1Contains = 0;
    for (AbstractMap.SimpleEntry<Integer, Integer> testValue : testValues) {
      if (map1.containsValue(testValue.getValue())) {
        map1Contains++;
      }
    }

    assertMatchSuccessfulOperationQuota(1, testValues.length, map1Contains, map2Contains);
  }
  private String getValueFrom(List<AbstractMap.SimpleEntry<String, String>> values, String key) {
    Iterator<AbstractMap.SimpleEntry<String, String>> iterator = values.iterator();
    while (iterator.hasNext()) {
      AbstractMap.SimpleEntry<String, String> entry = iterator.next();
      if (entry.getKey().toLowerCase().equals(key.toLowerCase())) return entry.getValue();
    }

    return "";
  }
예제 #6
0
  @Override
  public void run() {
    List<Reindeer> reindeer =
        readResource("/day14.txt").stream().map(Reindeer::of).collect(Collectors.toList());

    int winner1 =
        reindeer
            .stream()
            .map(r -> new AbstractMap.SimpleEntry<>(r, r.simulate(SECONDS)))
            .max((a, b) -> compare(a.getValue(), b.getValue()))
            .get()
            .getValue();
    printAnswer(winner1);

    List<AbstractMap.SimpleEntry<Reindeer, AtomicInteger>> scores =
        readResource("/day14.txt")
            .stream()
            .map(Reindeer::of)
            .map(r -> new AbstractMap.SimpleEntry<>(r, new AtomicInteger()))
            .collect(Collectors.toList());

    for (int i = 0; i < SECONDS; i++) {
      scores.forEach(e -> e.getKey().tick());

      List<AbstractMap.SimpleEntry<Reindeer, AtomicInteger>> sorted =
          scores
              .stream()
              .sorted((a, b) -> compare(b.getKey().distance, a.getKey().distance))
              .collect(Collectors.toList());

      for (AbstractMap.SimpleEntry<Reindeer, AtomicInteger> e : sorted) {
        if (e.getKey().distance != sorted.get(0).getKey().distance) {
          break;
        }
        e.getValue().incrementAndGet();
      }
    }

    int winner2 =
        scores
            .stream()
            .max((a, b) -> compare(a.getValue().get(), b.getValue().get()))
            .get()
            .getValue()
            .get();
    printAnswer(winner2);
  }
예제 #7
0
파일: MDP.java 프로젝트: xueyizou/ACASX_3D
  public Map<State_Ctrl, Double> getTransitionStatesAndProbs(State_Ctrl cstate, int actionCode) {
    Map<State_Ctrl, Double> TransitionStatesAndProbs = new LinkedHashMap<State_Ctrl, Double>();

    double targetV = Utils.getActionV(actionCode);
    double accel = Utils.getActionA(actionCode);
    ArrayList<AbstractMap.SimpleEntry<State_Ctrl, Double>> nextStateMapProbabilities =
        new ArrayList<>();

    if ((accel > 0 && targetV > cstate.getoVy() && cstate.getoVy() < UPPER_VY)
        || (accel < 0
            && targetV < cstate.getoVy()
            && cstate.getoVy() > -UPPER_VY)) { // own aircraft follows a RA other than COC	

      for (ThreeTuple<Double, Double, Double> sigmaPoint : sigmaPointsA) {
        double oAy = accel;
        double iAy = sigmaPoint.x2;
        double sigmaP = sigmaPoint.x3;

        double hP = cstate.getH() + (cstate.getiVy() - cstate.getoVy()) + 0.5 * (iAy - oAy);
        double oVyP = Math.max(-UPPER_VY, Math.min(UPPER_VY, cstate.getoVy() + oAy));
        double iVyP = Math.max(-UPPER_VY, Math.min(UPPER_VY, cstate.getiVy() + iAy));
        int raP = actionCode;

        int hIdxL = (int) Math.floor(hP / hRes);
        int oVyIdxL = (int) Math.floor(oVyP / oVRes);
        int iVyIdxL = (int) Math.floor(iVyP / iVRes);
        for (int i = 0; i <= 1; i++) {
          int hIdx = (i == 0 ? hIdxL : hIdxL + 1);
          int hIdxP = hIdx < -nh ? -nh : (hIdx > nh ? nh : hIdx);
          for (int j = 0; j <= 1; j++) {
            int oVzIdx = (j == 0 ? oVyIdxL : oVyIdxL + 1);
            int oVzIdxP = oVzIdx < -noVy ? -noVy : (oVzIdx > noVy ? noVy : oVzIdx);
            for (int k = 0; k <= 1; k++) {
              int iVzIdx = (k == 0 ? iVyIdxL : iVyIdxL + 1);
              int iVzIdxP = iVzIdx < -niVy ? -niVy : (iVzIdx > niVy ? niVy : iVzIdx);

              State_Ctrl nextState = new State_Ctrl(hIdxP, oVzIdxP, iVzIdxP, raP);
              double probability =
                  sigmaP
                      * (1 - Math.abs(hIdx - hP / hRes))
                      * (1 - Math.abs(oVzIdx - oVyP / oVRes))
                      * (1 - Math.abs(iVzIdx - iVyP / iVRes));
              nextStateMapProbabilities.add(
                  new SimpleEntry<State_Ctrl, Double>(nextState, probability));
            }
          }
        }
      }

    } else {
      for (ThreeTuple<Double, Double, Double> sigmaPoint : sigmaPointsB) {
        double oAy = sigmaPoint.x1;
        double iAy = sigmaPoint.x2;
        double sigmaP = sigmaPoint.x3;

        double hP = cstate.getH() + (cstate.getiVy() - cstate.getoVy()) + 0.5 * (iAy - oAy);
        double oVyP = Math.max(-UPPER_VY, Math.min(UPPER_VY, cstate.getoVy() + oAy));
        double iVyP = Math.max(-UPPER_VY, Math.min(UPPER_VY, cstate.getiVy() + iAy));
        int raP = actionCode;

        int hIdxL = (int) Math.floor(hP / hRes);
        int oVyIdxL = (int) Math.floor(oVyP / oVRes);
        int iVyIdxL = (int) Math.floor(iVyP / iVRes);
        for (int i = 0; i <= 1; i++) {
          int hIdx = (i == 0 ? hIdxL : hIdxL + 1);
          int hIdxP = hIdx < -nh ? -nh : (hIdx > nh ? nh : hIdx);
          for (int j = 0; j <= 1; j++) {
            int oVyIdx = (j == 0 ? oVyIdxL : oVyIdxL + 1);
            int oVyIdxP = oVyIdx < -noVy ? -noVy : (oVyIdx > noVy ? noVy : oVyIdx);
            for (int k = 0; k <= 1; k++) {
              int iVyIdx = (k == 0 ? iVyIdxL : iVyIdxL + 1);
              int iVyIdxP = iVyIdx < -niVy ? -niVy : (iVyIdx > niVy ? niVy : iVyIdx);

              State_Ctrl nextState = new State_Ctrl(hIdxP, oVyIdxP, iVyIdxP, raP);
              double probability =
                  sigmaP
                      * (1 - Math.abs(hIdx - hP / hRes))
                      * (1 - Math.abs(oVyIdx - oVyP / oVRes))
                      * (1 - Math.abs(iVyIdx - iVyP / iVRes));
              nextStateMapProbabilities.add(
                  new SimpleEntry<State_Ctrl, Double>(nextState, probability));
            }
          }
        }
      }
    }

    for (AbstractMap.SimpleEntry<State_Ctrl, Double> nextStateMapProb : nextStateMapProbabilities) {
      State_Ctrl nextState = nextStateMapProb.getKey();
      if (TransitionStatesAndProbs.containsKey(nextState)) {
        TransitionStatesAndProbs.put(
            nextState, TransitionStatesAndProbs.get(nextState) + nextStateMapProb.getValue());
      } else {
        TransitionStatesAndProbs.put(nextState, nextStateMapProb.getValue());
      }
    }
    return TransitionStatesAndProbs;
  }
예제 #8
0
 protected void loadHttpServlet(final AnyValue conf, final ClassFilter<? extends Servlet> filter)
     throws Exception {
   final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
   final String prefix = conf == null ? "" : conf.getValue("path", "");
   final String threadName = "[" + Thread.currentThread().getName() + "] ";
   List<FilterEntry<? extends Servlet>> list = new ArrayList(filter.getFilterEntrys());
   list.sort(
       (FilterEntry<? extends Servlet> o1,
           FilterEntry<? extends Servlet>
               o2) -> { // 必须保证WebSocketServlet优先加载, 因为要确保其他的HttpServlet可以注入本地模式的WebSocketNode
         boolean ws1 = WebSocketServlet.class.isAssignableFrom(o1.getType());
         boolean ws2 = WebSocketServlet.class.isAssignableFrom(o2.getType());
         if (ws1 == ws2) return o1.getType().getName().compareTo(o2.getType().getName());
         return ws1 ? -1 : 1;
       });
   final List<AbstractMap.SimpleEntry<String, String[]>> ss =
       sb == null ? null : new ArrayList<>();
   for (FilterEntry<? extends Servlet> en : list) {
     Class<HttpServlet> clazz = (Class<HttpServlet>) en.getType();
     if (Modifier.isAbstract(clazz.getModifiers())) continue;
     WebServlet ws = clazz.getAnnotation(WebServlet.class);
     if (ws == null || ws.value().length == 0) continue;
     final HttpServlet servlet = clazz.newInstance();
     resourceFactory.inject(servlet, this);
     final String[] mappings = ws.value();
     String pref = ws.repair() ? prefix : "";
     DefaultAnyValue servletConf = (DefaultAnyValue) en.getProperty();
     WebInitParam[] webparams = ws.initParams();
     if (webparams.length > 0) {
       if (servletConf == null) servletConf = new DefaultAnyValue();
       for (WebInitParam webparam : webparams) {
         servletConf.addValue(webparam.name(), webparam.value());
       }
     }
     this.httpServer.addHttpServlet(servlet, pref, servletConf, mappings);
     if (ss != null) {
       for (int i = 0; i < mappings.length; i++) {
         mappings[i] = pref + mappings[i];
       }
       ss.add(new AbstractMap.SimpleEntry<>(clazz.getName(), mappings));
     }
   }
   if (ss != null) {
     Collections.sort(
         ss,
         (AbstractMap.SimpleEntry<String, String[]> o1,
             AbstractMap.SimpleEntry<String, String[]> o2) -> o1.getKey().compareTo(o2.getKey()));
     int max = 0;
     for (AbstractMap.SimpleEntry<String, String[]> as : ss) {
       if (as.getKey().length() > max) max = as.getKey().length();
     }
     for (AbstractMap.SimpleEntry<String, String[]> as : ss) {
       sb.append(threadName).append(" Loaded ").append(as.getKey());
       for (int i = 0; i < max - as.getKey().length(); i++) {
         sb.append(' ');
       }
       sb.append("  mapping to  ").append(Arrays.toString(as.getValue())).append(LINE_SEPARATOR);
     }
   }
   if (sb != null && sb.length() > 0) logger.log(Level.INFO, sb.toString());
 }