AsyncIndexUpdate implements Runnable, Closeable { public AsyncIndexStats getIndexStats() { return indexStats; } AsyncIndexUpdate(@NotNull String name, @NotNull NodeStore store,
                            @NotNull IndexEditorProvider provider, boolean switchOnSync);  AsyncIndexUpdate(@NotNull String name, @NotNull NodeStore store,
                            @NotNull IndexEditorProvider provider, StatisticsProvider statsProvider, boolean switchOnSync);  AsyncIndexUpdate(@NotNull String name, @NotNull NodeStore store,
                            @NotNull IndexEditorProvider provider); static String checkValidName(String asyncName); static boolean isAsyncLaneName(String asyncName); @Override synchronized void run(); @Override void close(); static String leasify(String name); void setValidatorProviders(List<ValidatorProvider> validatorProviders); void setCorruptIndexHandler(TrackingCorruptIndexHandler corruptIndexHandler); boolean isClosed(); AsyncIndexStats getIndexStats(); boolean isFinished(); boolean isFailing(); void setIndexMBeanRegistration(IndexMBeanRegistration mbeanRegistration); String getName(); static final String PROP_ASYNC_NAME; }
@Test public void testAsyncExecutionStats() throws Exception { final Set<String> knownCheckpoints = Sets.newHashSet(); MemoryNodeStore store = new MemoryNodeStore(){ @Override public synchronized NodeState retrieve(@NotNull String checkpoint) { if (!knownCheckpoints.isEmpty() && !knownCheckpoints.contains(checkpoint)){ return null; } return super.retrieve(checkpoint); } }; IndexEditorProvider provider = new PropertyIndexEditorProvider(); NodeBuilder builder = store.getRoot().builder(); createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null) .setProperty(ASYNC_PROPERTY_NAME, "async"); builder.child("testRoot").setProperty("foo", "abc"); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider, statsProvider, false); runOneCycle(async); assertEquals(1, async.getIndexStats().getExecutionStats().getExecutionCounter().getCount()); runOneCycle(async); assertEquals(2, async.getIndexStats().getExecutionStats().getExecutionCounter().getCount()); long indexedNodeCount = async.getIndexStats().getExecutionStats().getIndexedNodeCount().getCount(); runOneCycle(async); assertEquals(indexedNodeCount, async.getIndexStats().getExecutionStats().getIndexedNodeCount().getCount()); builder = store.getRoot().builder(); builder.child("testRoot2").setProperty("foo", "abc"); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); runOneCycle(async); assertEquals(4, async.getIndexStats().getExecutionStats().getExecutionCounter().getCount()); builder = store.getRoot().builder(); builder.child("testRoot3").setProperty("foo", "abc"); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); knownCheckpoints.addAll(store.listCheckpoints()); runOneCycle(async); assertEquals(0, lastExecutionStats(async.getIndexStats().getExecutionCount())); }
@Test public void executionCountUpdatesOnRunWithoutAnyChangeInRepo() throws Exception { AsyncIndexUpdate async = new AsyncIndexUpdate("async", new MemoryNodeStore(), new PropertyIndexEditorProvider(), statsProvider, false); long execCnt1 = async.getIndexStats().getTotalExecutionCount(); runOneCycle(async); long execCnt2 = async.getIndexStats().getTotalExecutionCount(); runOneCycle(async); long execCnt3 = async.getIndexStats().getTotalExecutionCount(); assertNotEquals("execCnt1 " + execCnt1 + " and execCnt2 " + execCnt2 + " are same", execCnt1, execCnt2); assertNotEquals("execCnt2 " + execCnt2 + " and execCnt3 " + execCnt3 + " are same", execCnt2, execCnt3); }