@Test public void shouldBringIndexOnlineAndFlipOverToIndexAccessor() throws Exception { // given when(accessor.newUpdater(any(IndexUpdateMode.class))).thenReturn(updater); IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData()); life.start(); // when indexingService.createIndex(indexRule(0, labelId, propertyKeyId, PROVIDER_DESCRIPTOR)); IndexProxy proxy = indexingService.getProxyForRule(0); verify(populator, timeout(1000)).close(true); try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE)) { updater.process(add(10, "foo")); } // then assertEquals(InternalIndexState.ONLINE, proxy.getState()); InOrder order = inOrder(populator, accessor, updater); order.verify(populator).create(); order.verify(populator).close(true); order.verify(accessor).newUpdater(IndexUpdateMode.ONLINE); order.verify(updater).process(add(10, "foo")); order.verify(updater).close(); }
@Test public void shouldStillReportInternalIndexStateAsPopulatingWhenConstraintIndexIsDonePopulating() throws Exception { // given when(accessor.newUpdater(any(IndexUpdateMode.class))).thenReturn(updater); IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData()); life.start(); // when indexingService.createIndex( IndexRule.constraintIndexRule(0, labelId, propertyKeyId, PROVIDER_DESCRIPTOR, null)); IndexProxy proxy = indexingService.getProxyForRule(0); verify(populator, timeout(1000)).close(true); try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE)) { updater.process(add(10, "foo")); } // then assertEquals(InternalIndexState.POPULATING, proxy.getState()); InOrder order = inOrder(populator, accessor, updater); order.verify(populator).create(); order.verify(populator).close(true); order.verify(accessor).newUpdater(IndexUpdateMode.ONLINE); order.verify(updater).process(add(10, "foo")); order.verify(updater).close(); }
@Override public boolean awaitStoreScanCompleted() throws IndexPopulationFailedKernelException, InterruptedException { IndexProxy proxy; do { lock.readLock().lock(); proxy = delegate; lock.readLock().unlock(); } while (proxy.awaitStoreScanCompleted()); return true; }
@Test public void shouldDeliverUpdatesThatOccurDuringPopulationToPopulator() throws Exception { // given when(populator.newPopulatingUpdater()).thenReturn(updater); CountDownLatch latch = new CountDownLatch(1); doAnswer(afterAwaiting(latch)).when(populator).add(anyLong(), any()); IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData(add(1, "value1"))); life.start(); // when indexingService.createIndex(indexRule(0, labelId, propertyKeyId, PROVIDER_DESCRIPTOR)); IndexProxy proxy = indexingService.getProxyForRule(0); assertEquals(InternalIndexState.POPULATING, proxy.getState()); try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE)) { updater.process(add(2, "value2")); } latch.countDown(); verify(populator, timeout(1000)).close(true); // then assertEquals(InternalIndexState.ONLINE, proxy.getState()); InOrder order = inOrder(populator, accessor, updater); order.verify(populator).create(); order.verify(populator).add(1, "value1"); // this is invoked from indexAllNodes(), // empty because the id we added (2) is bigger than the one we indexed (1) order.verify(populator).newPopulatingUpdater(); order.verify(updater).close(); order.verify(populator).newPopulatingUpdater(); order.verify(updater).process(add(2, "value2")); order.verify(updater).close(); order.verify(populator).close(true); verifyNoMoreInteractions(updater); verifyNoMoreInteractions(populator); verifyZeroInteractions(accessor); }
@Override public InternalIndexState getState() { lock.readLock().lock(); try { return delegate.getState(); } finally { lock.readLock().unlock(); } }
@Override public SchemaIndexProvider.Descriptor getProviderDescriptor() { lock.readLock().lock(); try { return delegate.getProviderDescriptor(); } finally { lock.readLock().unlock(); } }
@Override public IndexReader newReader() throws IndexNotFoundKernelException { lock.readLock().lock(); try { return delegate.newReader(); } finally { lock.readLock().unlock(); } }
@Override public IndexDescriptor getDescriptor() { lock.readLock().lock(); try { return delegate.getDescriptor(); } finally { lock.readLock().unlock(); } }
@Override public void force() throws IOException { lock.readLock().lock(); try { delegate.force(); } finally { lock.readLock().unlock(); } }
@Override public void update(Iterable<NodePropertyUpdate> updates) throws IOException { lock.readLock().lock(); try { delegate.update(updates); } finally { lock.readLock().unlock(); } }
@Override public IndexPopulationFailure getPopulationFailure() throws IllegalStateException { lock.readLock().lock(); try { return delegate.getPopulationFailure(); } finally { lock.readLock().unlock(); } }
@Override public void validate() throws IndexPopulationFailedKernelException { lock.readLock().lock(); try { delegate.validate(); } finally { lock.readLock().unlock(); } }
@Override public Future<Void> drop() throws IOException { lock.readLock().lock(); try { closed = true; return delegate.drop(); } finally { lock.readLock().unlock(); } }
@Override public void recover(Iterable<NodePropertyUpdate> updates) throws IOException { // TODO Shouldn't need the lock lock.readLock().lock(); try { delegate.recover(updates); } finally { lock.readLock().unlock(); } }
@Override public void activate() { // use write lock, since activate() might call flip*() which acquires a write lock itself. lock.writeLock().lock(); try { delegate.activate(); } finally { lock.writeLock().unlock(); } }
@Test public void shouldBringConstraintIndexOnlineWhenExplicitlyToldTo() throws Exception { // given IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData()); life.start(); // when indexingService.createIndex( IndexRule.constraintIndexRule(0, labelId, propertyKeyId, PROVIDER_DESCRIPTOR, null)); IndexProxy proxy = indexingService.getProxyForRule(0); indexingService.activateIndex(0); // then assertEquals(ONLINE, proxy.getState()); InOrder order = inOrder(populator, accessor); order.verify(populator).create(); order.verify(populator).close(true); }
public static IndexProxy mockIndexProxy() throws IOException { IndexProxy result = mock(IndexProxy.class); when(result.drop()).thenReturn(FutureAdapter.VOID); when(result.close()).thenReturn(FutureAdapter.VOID); return result; }