示例#1
0
  private void getConnectionProperties(final Node node) {
    final NodeList childNodes = node.getChildNodes();

    for (int i = 0; i < childNodes.getLength(); ++i) {
      final Node childNode = childNodes.item(i);

      if (childNode.getNodeType() == Node.ELEMENT_NODE) {
        final String nodeName = childNode.getNodeName();
        if (nodeName.equals("property")) {
          final NamedNodeMap attributes = childNode.getAttributes();

          Node n = attributes.getNamedItem("name");
          ThreadContext.assertError(
              n != null,
              "DbAnalyse-options/connection-properties/property must contain a 'name' attribute");
          final String name = n.getNodeValue();

          n = attributes.getNamedItem("value");
          ThreadContext.assertError(
              n != null,
              "DbAnalyse-options/connection-properties/property must contain a 'value' attribute");
          final String value = n.getNodeValue();

          m_options.m_connectionProperties.add(E2.of(name, value));
        } else {
          ThreadContext.assertError(
              false, "[%s] unknown option element [%s]", getClass().getSimpleName(), nodeName);
        }
      }
    }
  }
  @Test
  public void testLogging() {
    try (IScope scope = new ExecutionScope()) {
      final E2<DummyLogger, DummyRemoteInstrumentationLogger> loggers = setupLoggers("fewidt");
      final DummyLogger localLogger = loggers.getE0();
      final DummyRemoteInstrumentationLogger remoteLogger = loggers.getE1();

      final String fatal = "fatal test string";
      final String error = "error test string";
      final String warn = "warn test string";
      final String info = "info test string";
      final String debug = "debug test string";
      final String trace = "trace test string";

      Logging.logInfoString(info);
      checkLogger(localLogger, null, null, null, info, null, null);
      checkLogger(remoteLogger, null, null, null, info, null, null);

      Logging.logFatalString(fatal);
      checkLogger(localLogger, fatal, null, null, info, null, null);
      checkLogger(remoteLogger, fatal, null, null, info, null, null);

      Logging.logErrorString(error);
      checkLogger(localLogger, fatal, error, null, info, null, null);
      checkLogger(remoteLogger, fatal, error, null, info, null, null);

      Logging.logWarnString(warn);
      checkLogger(localLogger, fatal, error, warn, info, null, null);
      checkLogger(remoteLogger, fatal, error, warn, info, null, null);

      Logging.logDebugString(debug);
      checkLogger(localLogger, fatal, error, warn, info, debug, null);
      checkLogger(remoteLogger, fatal, error, warn, info, null, null);

      Logging.logTraceString(trace);
      checkLogger(localLogger, fatal, error, warn, info, debug, trace);
      checkLogger(remoteLogger, fatal, error, warn, info, null, null);
    }
  }
  private E2<DummyLogger, DummyRemoteInstrumentationLogger> setupLoggers(
      final String levelsConfig) {
    // Red of Instrumentation.configure ()
    Logging.clearLoggers();

    final DummyRemoteInstrumentationLogger remoteLogger =
        new DummyRemoteInstrumentationLogger("fewi", getTempPath("log-remote.txt"));

    final List<ConsoleStringLogger> slaves =
        OUTPUT_TO_CONSOLE ? Arrays.asList(new ConsoleStringLogger()) : null;
    final DummyLogger localLogger =
        new DummyLogger(levelsConfig, slaves, getTempPath("log-local.txt"));
    Logging.addLogger(localLogger);

    Instrumentation.addInstrumentationListener(new InstrumentionStringLogger(localLogger));

    Instrumentation.addInstrumentationListener(remoteLogger);
    Logging.addLogger(remoteLogger);

    return E2.of(localLogger, remoteLogger);
  }
  @Test
  public void testInstrumentation() {
    try (IScope scope = new ExecutionScope()) {
      Instrumentation.setPolicyAsyncInstrumentation(false); // execute actions synchronously

      final E2<DummyLogger, DummyRemoteInstrumentationLogger> loggers = setupLoggers("fewi");
      final DummyLogger localLogger = loggers.getE0();
      final DummyRemoteInstrumentationLogger remoteLogger = loggers.getE1();

      if (true) {
        Instrumentation.publishExecutionSummary();
        checkInstrumentationListener(remoteLogger, 1, 0, 0, 0);
        checkLogger(localLogger, 0, 0, 0, 1, 0, 0);
        checkLogger(remoteLogger, 0, 0, 0, 0, 0, 0);
      }

      if (true) {
        final String name = "timelyOperation";
        Instrumentation.execute(
            name,
            200,
            () -> {
              HcUtil.pause(10);
            },
            name);

        Instrumentation.publishExecutionSummary();
        checkInstrumentationListener(remoteLogger, 2, 0, 0, 0);
        checkLogger(localLogger, 0, 0, 0, 2, 0, 0);
        checkLogger(remoteLogger, 0, 0, 0, 0, 0, 0);
      }

      if (true) {
        final String name = "slowOperation";
        Instrumentation.execute(
            name,
            10,
            () -> {
              HcUtil.pause(100);
            },
            name);

        Instrumentation.publishExecutionSummary();
        checkInstrumentationListener(remoteLogger, 3, 1, 1, 0);
        checkLogger(localLogger, 0, 0, 2, 3, 0, 0);
        checkLogger(remoteLogger, 0, 0, 0, 0, 0, 0);
      }

      if (true) {
        try {
          final String name = "failedTimelyOperation";
          Instrumentation.execute(
              name,
              200,
              () -> {
                HcUtil.pause(10);
                ThreadContext.assertFaultNotNull(null);
              },
              name);
        } catch (final Exception e) {
        }

        Instrumentation.publishExecutionSummary();
        checkInstrumentationListener(remoteLogger, 4, 1, 1, 1);
        checkLogger(localLogger, 2, 0, 2, 4, 0, 0);
        checkLogger(remoteLogger, 1, 0, 0, 0, 0, 0);
      }

      if (true) {
        try {
          final String name = "failedTimelyOperationException";
          Instrumentation.execute(
              name,
              200,
              () -> {
                HcUtil.pause(10);
                throw new RuntimeException("Ooops");
              },
              name);
        } catch (final Exception e) {
        }

        Instrumentation.publishExecutionSummary();
        checkInstrumentationListener(remoteLogger, 5, 1, 1, 2);
        checkLogger(localLogger, 4, 0, 2, 5, 0, 0);
        checkLogger(remoteLogger, 2, 0, 0, 0, 0, 0);
      }
    }
  }