private void stress(String desc) { long start = System.currentTimeMillis(); for (int i = 0; i < LOOP; i++) { broker.addPath("cc"); broker.addQueryData("a", "3"); broker.render(); } long duration = System.currentTimeMillis() - start; System.out.printf("%s, Loop: %d, Duration: %,d ms%n", desc, LOOP, duration); }
@Test public void withPrerender() { parent = (GenericURIBroker) new GenericURIBroker().fork(); setupBroker(parent); // parent是autoreset的,因此fork出来的broker会prerendering broker = (GenericURIBroker) parent.fork(); broker.addPath("cc"); broker.addQueryData("a", "3"); assertEquals("https://*****:*****@localhost/aa/bb/cc?a=1&b=2&a=3#ref", broker.render()); assertEquals(true, broker.renderer.isServerRendered()); stress("With Prerendering"); }
private void setupBroker(GenericURIBroker broker) { broker.setCharset("GBK"); // 避免LocaleUtil初始化的时间 broker.setServerScheme("https"); broker.setServerName("localhost"); broker.setServerPort(443); broker.setLoginUser("user"); broker.setLoginPassword("pass"); broker.setReference("ref"); broker.addPath("/aa/bb"); broker.addQueryData("a", 1); broker.addQueryData("b", 2); }