@Test public void testTrim() throws Exception { ReplicationServer replicationServer = null; JEReplicaDB replicaDB = null; try { TestCaseUtils.startServer(); replicationServer = configureReplicationServer(100, 5000); replicaDB = newReplicaDB(replicationServer); CSN[] csns = generateCSNs(1, 0, 5); replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[0], "uid")); replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[1], "uid")); replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[2], "uid")); DeleteMsg update4 = new DeleteMsg(TEST_ROOT_DN, csns[3], "uid"); // -- // Iterator tests with changes persisted assertFoundInOrder(replicaDB, csns[0], csns[1], csns[2]); assertNotFound(replicaDB, csns[4], AFTER_MATCHING_KEY); assertEquals(replicaDB.getOldestCSN(), csns[0]); assertEquals(replicaDB.getNewestCSN(), csns[2]); // -- // Cursor tests with changes persisted replicaDB.add(update4); assertFoundInOrder(replicaDB, csns[0], csns[1], csns[2], csns[3]); // Test cursor from existing CSN assertFoundInOrder(replicaDB, csns[2], csns[3]); assertFoundInOrder(replicaDB, csns[3]); assertNotFound(replicaDB, csns[4], AFTER_MATCHING_KEY); replicaDB.purgeUpTo(new CSN(Long.MAX_VALUE, 0, 0)); int count = 0; boolean purgeSucceeded = false; final CSN expectedNewestCSN = csns[3]; do { Thread.sleep(10); final CSN oldestCSN = replicaDB.getOldestCSN(); final CSN newestCSN = replicaDB.getNewestCSN(); purgeSucceeded = oldestCSN.equals(expectedNewestCSN) && newestCSN.equals(expectedNewestCSN); count++; } while (!purgeSucceeded && count < 100); assertTrue(purgeSucceeded); } finally { shutdown(replicaDB); remove(replicationServer); } }
@Ignore @Test public void testWithHazelcastConfiguration() throws Exception { // wrong use!! ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URI uri = classLoader.getResource("hazelcast-jcache.xml").toURI(); try (CachingProvider provider = Caching.getCachingProvider(); CacheManager manager = provider.getCacheManager(uri, classLoader); Cache<String, String> cache = manager.getCache("testCache")) { cache.put("key1", "value1"); cache.put("key2", "value2"); TimeUnit.SECONDS.sleep(1); cache.get("key2"); TimeUnit.SECONDS.sleep(2); assertThat(cache.get("key1")).isNull(); assertThat(cache.get("key2")).isEqualTo("value2"); } }
/** Tests the maximum persistent search limit imposed by the server. */ @Test public void testMaxPSearch() throws Exception { TestCaseUtils.initializeTestBackend(true); // Modify the configuration to allow only 1 concurrent persistent search. InternalClientConnection conn = getRootConnection(); LDAPAttribute attr = new LDAPAttribute("ds-cfg-max-psearches", "1"); ArrayList<RawModification> mods = new ArrayList<>(); mods.add(new LDAPModification(ModificationType.REPLACE, attr)); ModifyOperation modifyOperation = conn.processModify(ByteString.valueOf("cn=config"), mods); assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); // Create a persistent search request. Set<PersistentSearchChangeType> changeTypes = EnumSet.of(ADD, DELETE, MODIFY, MODIFY_DN); SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.BASE_OBJECT) .setTypesOnly(true) .addAttribute("cn") .addControl(new PersistentSearchControl(changeTypes, true, true)); final InternalSearchOperation search = conn.processSearch(request); Thread t = new Thread( new Runnable() { @Override public void run() { try { search.run(); } catch (Exception ex) { } } }, "Persistent Search Test"); t.start(); t.join(2000); // Create a persistent search request. final String[] args = { "-D", "cn=Directory Manager", "-w", "password", "-h", "127.0.0.1", "-p", String.valueOf(TestCaseUtils.getServerLdapPort()), "-b", "o=test", "-s", "sub", "-C", "ps:add:true:true", "--noPropertiesFile", "(objectClass=*)" }; assertEquals(LDAPSearch.mainSearch(args, false, true, null, System.err), 11); // cancel the persisting persistent search. search.cancel(new CancelRequest(true, LocalizableMessage.EMPTY)); }