Exemple #1
0
  public static void main(String[] args) {
    LoanConsumer loanConsumer = null;
    try {
      String config = SystemUtils.getCommandLineOption("-config", args);
      if (StringUtils.isNotBlank(config)) {
        loanConsumer = new LoanConsumer(config);

        int i = 100;
        String requests = SystemUtils.getCommandLineOption("-req", args);
        if (requests != null) {
          i = Integer.parseInt(requests);
        }

        String sync = SystemUtils.getCommandLineOption("-sync", args);
        if (sync != null) {
          synchronous = Boolean.valueOf(sync).booleanValue();
        }

        if (synchronous) {
          long start = System.currentTimeMillis();
          List results = loanConsumer.requestSend(i, "vm://LoanBrokerRequests");
          System.out.println("Number or quotes received: " + results.size());
          List output = new ArrayList(results.size());
          int x = 1;
          for (Iterator iterator = results.iterator(); iterator.hasNext(); x++) {
            LoanQuote quote = (LoanQuote) iterator.next();
            output.add(x + ". " + quote.toString());
          }
          System.out.println(StringMessageUtils.getBoilerPlate(output, '*', 80));
          long cur = System.currentTimeMillis();
          System.out.println(DateUtils.getFormattedDuration(cur - start));
          System.out.println("Avg request: " + ((cur - start) / x));
        } else {
          loanConsumer.requestDispatch(i, "vm://LoanBrokerRequests");
        }
      } else {
        loanConsumer = new LoanConsumer(getInteractiveConfig());
        loanConsumer.run(synchronous);
      }

    } catch (Exception e) {
      System.err.println(e.getMessage());
      e.printStackTrace(System.err);
      System.exit(1);
    }
  }
  @Test
  public void testEnvironment() throws Exception {
    Map env = SystemUtils.getenv();
    assertNotNull(env);
    assertFalse(env.isEmpty());
    assertSame(env, SystemUtils.getenv());

    String envVarToTest = "PATH";
    if (SystemUtils.IS_OS_WINDOWS) {
      // Depending on the presence of Cygwin, it might be one or the other.
      if (env.get(envVarToTest) == null) {
        envVarToTest = "Path";
      }
    }

    assertNotNull(env.get(envVarToTest));
  }
  @Test
  public void testSimpleTextFileStore() throws Exception {
    final IdempotentMessageFilter filter = idempotentMessageFilterFromFlow("simpleTextFileStore");

    final ObjectStore<?> store = filter.getStore();
    assertEquals(TextFileObjectStore.class, store.getClass());

    final TextFileObjectStore fileStore = (TextFileObjectStore) store;
    assertEquals("the-store", fileStore.getName());

    final File tmpDir = SystemUtils.getJavaIoTmpDir();
    assertEquals(tmpDir.getCanonicalPath(), new File(fileStore.getDirectory()).getCanonicalPath());

    assertEquals(1000, fileStore.getEntryTTL());
    assertEquals(2000, fileStore.getExpirationInterval());
    assertEquals(3000, fileStore.getMaxEntries());
  }
Exemple #4
0
 public static String getenv(String name) {
   return (String) SystemUtils.getenv().get(name);
 }
  @Test
  public void testParsePropertyDefinitions() {
    Map expected = Collections.EMPTY_MAP;
    String input;

    assertEquals(expected, SystemUtils.parsePropertyDefinitions(null));
    assertEquals(expected, SystemUtils.parsePropertyDefinitions(""));
    assertEquals(expected, SystemUtils.parsePropertyDefinitions(" "));
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("foo"));
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("-D"));
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("-D="));

    expected = Collections.singletonMap("-D", "true");
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("-D-D"));

    expected = Collections.singletonMap("-D-D", "true");
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("-D-D-D"));

    expected = Collections.singletonMap("-D-D-D", "true");
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("-D-D-D-D"));

    assertEquals(Collections.EMPTY_MAP, SystemUtils.parsePropertyDefinitions("-D=noKey"));
    assertEquals(Collections.EMPTY_MAP, SystemUtils.parsePropertyDefinitions("=-D"));
    assertEquals(Collections.EMPTY_MAP, SystemUtils.parsePropertyDefinitions("foo =foo foo"));

    expected = Collections.singletonMap("k", "true");
    assertEquals(expected, SystemUtils.parsePropertyDefinitions(" -Dk "));

    expected = Collections.singletonMap("key", "true");
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("-Dkey"));

    expected = Collections.singletonMap("k", "v");
    assertEquals(expected, SystemUtils.parsePropertyDefinitions(" -Dk=v "));

    expected = Collections.singletonMap("key", "value");
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("-Dkey=value"));

    expected = Collections.singletonMap("key", "quoted");
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("-Dkey=\"quoted\""));

    expected =
        MapUtils.mapWithKeysAndValues(
            HashMap.class, new String[] {"key", "foo"}, new String[] {"-Dvalue", "bar"});
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("-Dkey=-Dvalue -Dfoo=bar"));

    assertEquals(Collections.EMPTY_MAP, SystemUtils.parsePropertyDefinitions("-D=-Dfoo-D== =foo"));

    expected = Collections.singletonMap("key", "split value");
    assertEquals(expected, SystemUtils.parsePropertyDefinitions("-Dkey=\"split value\""));

    expected =
        MapUtils.mapWithKeysAndValues(
            HashMap.class, new String[] {"key1", "key2"}, new String[] {"split one", "split two"});
    input = "-Dkey1=\"split one\" -Dkey2=\"split two\" ";
    assertEquals(expected, SystemUtils.parsePropertyDefinitions(input));

    expected = Collections.singletonMap("key", "open end");
    input = "-Dkey=\"open end";
    assertEquals(expected, SystemUtils.parsePropertyDefinitions(input));

    expected =
        MapUtils.mapWithKeysAndValues(
            HashMap.class,
            new String[] {"keyOnly", "mule.foo", "mule.bar"},
            new String[] {"true", "xfoo", "xbar"});
    input = "  standalone key=value -D -D= -DkeyOnly -D=noKey -Dmule.foo=xfoo -Dmule.bar=xbar ";
    assertEquals(expected, SystemUtils.parsePropertyDefinitions(input));
  }