DbInsertion insertion = new DbInsertion(rec, null, null, new TestLogFileTask(em, log), 100L, null, "method");
insertion.start(new ExceptionsData());
//waitLogsParsed();
List<Slowness> all =
PersistenceUtils.getAll(em, Slowness.class);
Slowness rootSlowness = all.get(all.size() - 1);
rootId = rootSlowness.getId();
List<Nbuser> users = PersistenceUtils.getAll(em, Nbuser.class);
Nbuser user = null;
for (Nbuser us : users) {
if (userName.equals(us.getName())) {
user = us;
}
}
all = PersistenceUtils.getAll(em, Slowness.class);
rootSlowness = all.get(all.size() - 1);
assertNotNull(rootSlowness);
assertEquals(1, rootSlowness.getReportId().getDuplicates(em));
assertEquals(1, rootSlowness.getReportId().getDuplicatesFromDistinctUsers(em));
assertEquals(1, rootSlowness.getReportId().getDuplicatesFromOneUser(em, user));
session = 2;
log = new Logfile(userId, session);
// -- refresh persistence context ---//
em.getTransaction().commit();
em.close();
em = perUtils.createEntityManager();
em.getTransaction().begin();
all = PersistenceUtils.getAll(em, Slowness.class);
rootSlowness = all.get(all.size() - 1);
rootSlowness = insert(em, new DbInsertion(rec, null, null, new TestLogFileTask(em, log), 100L, null, "method"));
assertEquals(2, rootSlowness.getReportId().getDuplicates(em));
assertEquals(1, rootSlowness.getReportId().getDuplicatesFromDistinctUsers(em));
assertEquals(2, rootSlowness.getReportId().getDuplicatesFromOneUser(em, user));
session = 3;
log = new Logfile(userId, session);
// -- refresh persistence context ---//
em.getTransaction().commit();
em.close();
em = perUtils.createEntityManager();
em.getTransaction().begin();
all = PersistenceUtils.getAll(em, Slowness.class);
rootSlowness = all.get(all.size() - 1);
rootSlowness = insert(em, new DbInsertion(rec, null, null, new TestLogFileTask(em, log), 100L, null, "method"));
assertEquals(3, rootSlowness.getReportId().getDuplicates(em));
assertEquals(1, rootSlowness.getReportId().getDuplicatesFromDistinctUsers(em));
assertEquals(3, rootSlowness.getReportId().getDuplicatesFromOneUser(em, user));
userName = "exceptions";
params.set(3, userName);
params.set(6, "petrzajac");
rec.setParameters(params.toArray());
session = 4;
log = new Logfile(userId, session);
// -- refresh persistence context ---//
em.getTransaction().commit();
em.close();
em = perUtils.createEntityManager();
em.getTransaction().begin();
all = PersistenceUtils.getAll(em, Slowness.class);
rootSlowness = all.get(all.size() - 1);
rootSlowness = insert(em, new DbInsertion(rec, null, null, new TestLogFileTask(em, log), 100L, null, "method"));
users = PersistenceUtils.getAll(em, Nbuser.class);
Iterator<Nbuser> userIt = users.iterator();
Nbuser user2 = null;
while (userIt.hasNext()) {
user2 = userIt.next();
if (user2.getName().equals(userName)) {
break;
}
}
assertEquals(4, rootSlowness.getReportId().getDuplicates(em));
assertEquals(2, rootSlowness.getReportId().getDuplicatesFromDistinctUsers(em));
assertEquals(3, rootSlowness.getReportId().getDuplicatesFromOneUser(em, user));
assertEquals(1, rootSlowness.getReportId().getDuplicatesFromOneUser(em, user2));
session = 5;
log = new Logfile(userId, session);
rootSlowness = insert(em, new DbInsertion(rec, null, null, new TestLogFileTask(em, log), 100L, null, "method"));
// -- refresh persistence context ---//
em.getTransaction().commit();
em.close();
em = perUtils.createEntityManager();
em.getTransaction().begin();
all = PersistenceUtils.getAll(em, Slowness.class);
rootSlowness = all.get(all.size() - 1);
assertEquals(5, rootSlowness.getReportId().getDuplicates(em));
assertEquals(2, rootSlowness.getReportId().getDuplicatesFromDistinctUsers(em));
assertEquals(3, rootSlowness.getReportId().getDuplicatesFromOneUser(em, user));
assertEquals(2, rootSlowness.getReportId().getDuplicatesFromOneUser(em, user2));
em.getTransaction().commit();
em.close();
}