/** testUserInsertFindDelete */ @Test public void testUserInsertFindDelete() { // create identity and property Identity id = JunitTestHelper.createAndPersistIdentityAsUser("user-prop-" + UUID.randomUUID().toString()); Property p = pm.createUserPropertyInstance( id, "catuser", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); dbInstance.commitAndCloseSession(); p = pm.findUserProperty(id, "catuser", "TestProperty"); assertNotNull(p); assertEquals(p.getStringValue(), "stringValue"); assertEquals(p.getFloatValue(), new Float(1.1)); assertEquals(p.getTextValue(), "textValue"); pm.deleteProperty(p); p = pm.findUserProperty(id, "catuser", "TestProperty"); assertNull(p); dbInstance.commitAndCloseSession(); }
/** * Performance test of 500 propertycreations per type. Rename to testPerf500Properties to include * this test in the test suit. */ @Test public void testPerf500Properties() { // create identity, group and resource OLATResource res = JunitTestHelper.createRandomResource(); Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("prop-5-" + UUID.randomUUID().toString()); BusinessGroup group = businessGroupService.createBusinessGroup( identity, "a buddygroup", "a desc", -1, -1, false, false, null); dbInstance.commitAndCloseSession(); long start, stop; long count = 500; // create generic proerties log.info("----------------------------------------------------------------"); log.info("Performance test startet. Running " + count + " cycles per test."); log.info("CREATE generic property test started..."); start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Property p = pm.createPropertyInstance( identity, group, res, "perf500", "TestProperty" + i, new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); if (i % 50 == 0) { dbInstance.commitAndCloseSession(); } } dbInstance.commitAndCloseSession(); stop = System.currentTimeMillis(); log.info( "CREATE generic property test: " + (stop - start) + " ms (" + (count * 1000 / (stop - start)) + "/sec)"); // some find identitites tests List<Identity> ids = pm.findIdentitiesWithProperty(null, null, "perf500", null, false); Assert.assertNotNull("Identities cannot be null", ids); Assert.assertFalse("Identities cannot be empty", ids.isEmpty()); Assert.assertTrue("Identities must contains reference identity", ids.contains(identity)); // create course and user properties log.info("Preparing user/group properties test. Creating additional properties.."); start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Property pUser = pm.createUserPropertyInstance( identity, "perf500", "TestProperty" + i, new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(pUser); if (i % 50 == 0) { dbInstance.commitAndCloseSession(); } } dbInstance.commitAndCloseSession(); stop = System.currentTimeMillis(); log.info("Ready : " + (stop - start) + " ms (" + (2 * count * 1000 / (stop - start)) + "/sec)"); log.info("Starting find tests. DB holds " + count * 3 + " records."); // find generic property test log.info("FIND generic property test started..."); start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Property p = pm.findProperty(identity, group, res, "perf500", "TestProperty" + i); assertNotNull("Must find the p (count=" + i + ")", p); dbInstance.commitAndCloseSession(); } stop = System.currentTimeMillis(); log.info( "FIND generic property test: " + (stop - start) + " ms (" + (count * 1000 / (stop - start)) + "/sec)"); // find user property test log.info("FIND user property test started..."); start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Property p = pm.findUserProperty(identity, "perf500", "TestProperty" + i); assertNotNull("Must find the p (count=" + i + ")", p); dbInstance.commitAndCloseSession(); } stop = System.currentTimeMillis(); log.info( "FIND user property test: " + (stop - start) + " ms (" + (count * 1000 / (stop - start)) + "/sec)"); // find & delete log.info("FIND and DELETE generic property test started..."); start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Property p = pm.findUserProperty(identity, "perf500", "TestProperty" + i); pm.deleteProperty(p); } stop = System.currentTimeMillis(); log.info( "FIND and DELETE generic property test: " + (stop - start) + " ms (" + (count * 1000 / (stop - start)) + "/sec)"); log.info("----------------------------------------------------------------"); log.info("Performance test finished."); }