Esempio n. 1
0
  @Test
  public void testAsyncHttpServer() {
    Log.debugging();

    On.req(
        req -> {
          U.must(!req.isAsync());
          req.async();
          U.must(req.isAsync());

          Jobs.after(10, TimeUnit.MILLISECONDS)
              .run(
                  () -> {
                    IO.write(req.out(), "O");

                    Jobs.after(10, TimeUnit.MILLISECONDS)
                        .run(
                            () -> {
                              IO.write(req.out(), "K");
                              req.done();
                            });
                  });

          return req;
        });

    Self.get("/").expect("OK").benchmark(1, 100, 10000);
    Self.post("/").expect("OK").benchmark(1, 100, 10000);
  }
Esempio n. 2
0
  @Test
  public void testCompile() throws Exception {

    Compilation compilation =
        Compile.compile(
            IO.load("test1.java"),
            IO.load("mixin.java"),
            "public class Book { String title; int x = 1234; } class Foo {}",
            "public class Bar extends Foo {}",
            "public class Fg extends Foo {}");

    Set<Class<?>> classes = compilation.loadClasses();
    eq(classes.size(), 10);

    Set<String> classNames = compilation.getClassNames();
    D.print(classNames);

    eq(Cls.classMap(classes).get("Main").getAnnotations().length, 2);

    Set<String> expectedClasses =
        U.set(
            "abc.Main",
            "abc.Main$1",
            "abc.Person",
            "abc.Person$Insider",
            "abc.PersonService",
            "Book",
            "Foo",
            "Bar",
            "Fg",
            "mixo.Mixin");
    eq(classNames, expectedClasses);

    for (String clsName : expectedClasses) {
      Class<?> cls = compilation.loadClass(clsName);
      notNull(cls);
      eq(cls.getName(), clsName);
    }

    Class<?> mainClass = compilation.loadClass("abc.Main");
    Method main = Cls.getMethod(mainClass, "main", String[].class);

    Cls.invoke(main, null, new Object[] {new String[] {}});
  }
  @Test
  public void testConfigRootAndFileSetup() {
    String dir = createTempDir("app");

    IO.save(Msc.path(dir, "the-config.yml"), "id: abc2");

    Env.setArgs("root=" + dir, "config=the-config");

    eq(Conf.ROOT.entry("id").getOrNull(), "abc2");
  }
Esempio n. 4
0
  @Test
  public void testAsyncHttpServer2() {
    On.req(
        req ->
            Jobs.after(10, TimeUnit.MILLISECONDS)
                .run(
                    () -> {
                      IO.write(req.out(), "A");

                      Jobs.after(10, TimeUnit.MILLISECONDS)
                          .run(
                              () -> {
                                IO.write(req.out(), "SYNC");
                                req.done();
                              });
                    }));

    Self.get("/").expect("ASYNC").benchmark(1, 100, 10000);
    Self.post("/").expect("ASYNC").benchmark(1, 100, 10000);
  }
Esempio n. 5
0
 protected String resourceMD5(String filename) throws IOException, URISyntaxException {
   return Crypto.md5(FileUtils.readFileToByteArray(new File(IO.resource(filename).toURI())));
 }