DocumentNodeStoreService { @Activate protected void activate(ComponentContext context, Configuration config) throws Exception { closer = Closer.create(); this.config = DocumentNodeStoreServiceConfiguration.create(context, configurationAdmin, preset.configuration, config); this.context = context; whiteboard = new OsgiWhiteboard(context.getBundleContext()); executor = new WhiteboardExecutor(); executor.start(whiteboard); customBlobStore = this.config.customBlobStore(); documentStoreType = DocumentStoreType.fromString(this.config.documentStoreType()); registerNodeStoreIfPossible(); }   static final String CONTINUOUS_RGC_EXPR; static final String CLASSIC_RGC_EXPR; static final long DEFAULT_RGC_TIME_LIMIT_SECS; static final double DEFAULT_RGC_DELAY_FACTOR; static final String CUSTOM_BLOB_STORE; static final String PROP_REV_RECOVERY_INTERVAL; static final String PROP_DS_TYPE; }
@Test public void journalPropertyTracker() throws Exception { MockOsgi.setConfigForPid(context.bundleContext(), PID, newConfig(repoHome)); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore store = context.getService(DocumentNodeStore.class); assertEquals(0, store.getJournalPropertyHandlerFactory().getServiceCount()); context.registerService(JournalPropertyService.class, mock(JournalPropertyService.class)); assertEquals(1, store.getJournalPropertyHandlerFactory().getServiceCount()); }
@Test public void setUpdateLimit() throws Exception { Map<String, Object> config = newConfig(repoHome); config.put(DocumentNodeStoreServiceConfiguration.PROP_UPDATE_LIMIT, 17); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore store = context.getService(DocumentNodeStore.class); assertEquals(17, store.getUpdateLimit()); }
@Test public void keepAlive() throws Exception { Map<String, Object> config = newConfig(repoHome); config.put(DocumentNodeStoreServiceConfiguration.PROP_SO_KEEP_ALIVE, true); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore store = context.getService(DocumentNodeStore.class); MongoDocumentStore mds = getMongoDocumentStore(store); MongoClient client = MongoDocumentStoreTestHelper.getClient(mds); assertTrue(client.getMongoClientOptions().isSocketKeepAlive()); }
@Test public void continuousRGCDefault() throws Exception { Map<String, Object> config = newConfig(repoHome); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); boolean jobScheduled = false; for (Runnable r : context.getServices(Runnable.class, "(scheduler.expression=\\*/5 \\* \\* \\* \\* ?)")) { jobScheduled |= r.getClass().equals(DocumentNodeStoreService.RevisionGCJob.class); } assertTrue(jobScheduled); }
@Test public void continuousRGCJobAsSupplier() throws Exception { Map<String, Object> config = newConfig(repoHome); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); Runnable rgcJob = null; for (Runnable r : context.getServices(Runnable.class, null)) { if (r.getClass().equals(DocumentNodeStoreService.RevisionGCJob.class)) { rgcJob = r; } } assertNotNull(rgcJob); assertTrue(rgcJob instanceof Supplier); assertNotNull(((Supplier<String>) rgcJob).get()); }
@Test public void persistentCacheExclude() throws Exception{ Map<String, Object> config = newConfig(repoHome); config.put("persistentCacheIncludes", new String[] {"/a/b", "/c/d ", null}); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore dns = context.getService(DocumentNodeStore.class); assertTrue(dns.getNodeCachePredicate().apply(Path.fromString("/a/b/c"))); assertTrue(dns.getNodeCachePredicate().apply(Path.fromString("/c/d/e"))); assertFalse(dns.getNodeCachePredicate().apply(Path.fromString("/x"))); }
@Test public void preset() throws Exception { MockOsgi.setConfigForPid(context.bundleContext(), Configuration.PRESET_PID, DocumentNodeStoreServiceConfiguration.PROP_SO_KEEP_ALIVE, true); MockOsgi.activate(preset, context.bundleContext()); MockOsgi.setConfigForPid(context.bundleContext(), PID, newConfig(repoHome)); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore store = context.getService(DocumentNodeStore.class); MongoDocumentStore mds = getMongoDocumentStore(store); assertNotNull(mds); MongoClient client = MongoDocumentStoreTestHelper.getClient(mds); assertTrue(client.getMongoClientOptions().isSocketKeepAlive()); }
@Test public void presetOverride() throws Exception { MockOsgi.setConfigForPid(context.bundleContext(), Configuration.PRESET_PID, DocumentNodeStoreServiceConfiguration.PROP_SO_KEEP_ALIVE, true); MockOsgi.activate(preset, context.bundleContext()); Map<String, Object> config = newConfig(repoHome); config.put(DocumentNodeStoreServiceConfiguration.PROP_SO_KEEP_ALIVE, false); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore store = context.getService(DocumentNodeStore.class); MongoDocumentStore mds = getMongoDocumentStore(store); MongoClient client = MongoDocumentStoreTestHelper.getClient(mds); assertFalse(client.getMongoClientOptions().isSocketKeepAlive()); }
@Test public void strictLeaseCheckMode() { Map<String, Object> config = newConfig(repoHome); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore dns = context.getService(DocumentNodeStore.class); assertEquals(LeaseCheckMode.STRICT, dns.getClusterInfo().getLeaseCheckMode()); }
@Test public void lenientLeaseCheckMode() { Map<String, Object> config = newConfig(repoHome); config.put("leaseCheckMode", LeaseCheckMode.LENIENT.name()); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore dns = context.getService(DocumentNodeStore.class); assertEquals(LeaseCheckMode.LENIENT, dns.getClusterInfo().getLeaseCheckMode()); }
@Test public void revisionGcDelayFactorCheckMode() { Map<String, Object> config = newConfig(repoHome); double delayFactor = 0.25; config.put("versionGCDelayFactor", delayFactor); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); Runnable rgcJob = null; for (Runnable r : context.getServices(Runnable.class, null)) { if (r.getClass().equals(DocumentNodeStoreService.RevisionGCJob.class)) { rgcJob = r; } } assertNotNull(rgcJob); rgcJob.run(); DocumentNodeStore dns = context.getService(DocumentNodeStore.class); assertEquals(delayFactor, dns.getVersionGarbageCollector().getOptions().delayFactor, 0.001); }