Пример #1
0
  @Test
  public void testPuts() {
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();

    MyTestObject object = new MyTestObject();
    object.setName("Scooby doo");
    object.setAge(100);
    Date now = new Date();
    object.setBirthday(now);
    em.persist(object);

    System.out.println(em.getTotalOpStats());
    Assert.assertEquals(1, em.getTotalOpStats().getPuts());

    object.setId(null);
    em.persist(object);
    Assert.assertEquals(2, em.getTotalOpStats().getPuts());

    em.close();

    // New EntityManager and same op
    em = (EntityManagerSimpleJPA) factory.createEntityManager();

    object = new MyTestObject();
    object.setName("Scooby doo");
    object.setAge(100);
    object.setBirthday(now);
    em.persist(object);

    System.out.println(em.getTotalOpStats());
    Assert.assertEquals(1, em.getTotalOpStats().getPuts());
    Assert.assertEquals(3, em.getGlobalOpStats().getPuts());

    em.close();
  }
Пример #2
0
  @Test
  public void testPutQueryDelete() throws ExecutionException, InterruptedException {
    int numItems = 1;
    String x;
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
    PerformanceTestObject o = new PerformanceTestObject();
    o.setS1("first to create domain");
    em.persist(o);
    StopWatch stopWatch = new StopWatch();

    String s1a = "attribute1";
    String s2a = "attribute2";
    Future<PerformanceTestObject> lastFuture = null;
    stopWatch.start();
    for (int i = 0; i < numItems; i++) {
      o = new PerformanceTestObject();
      o.setS1(s1a);
      o.setS2(s2a);
      lastFuture = em.persistAsync(o);
    }
    lastFuture.get(); // not 100% accurate, but good enough
    stopWatch.stop();
    System.out.println(
        "puts duration="
            + stopWatch.getTime()
            + ", "
            + em.getTotalOpStats().getPuts()
            + " items put.");

    Thread.sleep(5000);

    stopWatch.reset();
    stopWatch.start();
    Query query = em.createQuery("select o from PerformanceTestObject o");
    List<PerformanceTestObject> resultList = query.getResultList();
    System.out.println("iterating result list...");
    int i = 0;
    for (PerformanceTestObject performanceTestObject : resultList) {

      i++;
      if (i % 100 == 0) {
        System.out.println(i);
      }
    }
    stopWatch.stop();
    System.out.println(
        "query ALL duration="
            + stopWatch.getTime()
            + ", "
            + em.getTotalOpStats().getGets()
            + " items got.");

    stopWatch.reset();
    stopWatch.start();
    System.out.println("Deleting ALL...");
    for (PerformanceTestObject performanceTestObject : resultList) {
      lastFuture = em.removeAsync(o);
    }
    lastFuture.get();
    stopWatch.stop();
    System.out.println(
        "delete duration=" + stopWatch.getTime() + ", " + resultList.size() + " items deleted.");
    System.out.println("sleeping...");
    Thread.sleep(30000);

    em.close();
  }