use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.
the class KernelExtensionsTest method shouldConsultUnsatisfiedDependencyHandler.
@Test
public void shouldConsultUnsatisfiedDependencyHandler() throws Exception {
// GIVEN
KernelContext context = mock(KernelContext.class);
UnsatisfiedDependencyStrategy handler = mock(UnsatisfiedDependencyStrategy.class);
// that hasn't got anything.
Dependencies dependencies = new Dependencies();
TestingExtensionFactory extensionFactory = new TestingExtensionFactory();
KernelExtensions extensions = new KernelExtensions(context, extensions(extensionFactory), dependencies, handler);
// WHEN
LifeSupport life = new LifeSupport();
life.add(extensions);
try {
life.start();
// THEN
verify(handler).handle(eq(extensionFactory), any(UnsatisfiedDependencyException.class));
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.
the class QueryEngineProviderTest method shouldPickTheOneAndOnlyQueryEngineAvailable.
@Test
public void shouldPickTheOneAndOnlyQueryEngineAvailable() throws Throwable {
// Given
QueryEngineProvider provider = mock(QueryEngineProvider.class);
when(provider.enginePriority()).thenReturn(1);
Dependencies deps = new Dependencies();
GraphDatabaseAPI graphAPI = mock(GraphDatabaseAPI.class);
QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
when(provider.createEngine(any(), any())).thenReturn(executionEngine);
// When
Iterable<QueryEngineProvider> providers = Iterables.asIterable(provider);
QueryExecutionEngine engine = QueryEngineProvider.initialize(deps, graphAPI, providers);
// Then
assertSame(executionEngine, engine);
}
use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.
the class CsvOutputTest method setup.
@Before
public void setup() {
File storeDir = directory.directory();
kernelContext = new SimpleKernelContext(storeDir, DatabaseInfo.UNKNOWN, new Dependencies());
}
use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.
the class IndexWorkSyncTransactionApplicationStressIT method shouldApplyIndexUpdatesInWorkSyncedBatches.
@Test
public void shouldApplyIndexUpdatesInWorkSyncedBatches() throws Exception {
// GIVEN
long duration = parseTimeMillis.apply(System.getProperty(getClass().getName() + ".duration", "2s"));
int numThreads = Integer.getInteger(getClass().getName() + ".numThreads", Runtime.getRuntime().availableProcessors());
RecordStorageEngine storageEngine = storageEngineRule.getWith(fileSystemRule.get(), pageCacheRule.getPageCache(fileSystemRule.get())).storeDirectory(directory.directory()).indexProvider(new InMemoryIndexProvider()).build();
storageEngine.apply(tx(asList(createIndexRule(InMemoryIndexProviderFactory.PROVIDER_DESCRIPTOR, 1, SchemaBoundary.map(descriptor)))), TransactionApplicationMode.EXTERNAL);
Dependencies dependencies = new Dependencies();
storageEngine.satisfyDependencies(dependencies);
IndexProxy index = dependencies.resolveDependency(IndexingService.class).getIndexProxy(descriptor);
awaitOnline(index);
// WHEN
Workers<Worker> workers = new Workers<>(getClass().getSimpleName());
final AtomicBoolean end = new AtomicBoolean();
for (int i = 0; i < numThreads; i++) {
workers.start(new Worker(i, end, storageEngine, 10, index));
}
// let the threads hammer the storage engine for some time
Thread.sleep(duration);
end.set(true);
// THEN (assertions as part of the workers applying transactions)
workers.awaitAndThrowOnError(RuntimeException.class);
}
use of org.neo4j.kernel.impl.util.Dependencies in project neo4j by neo4j.
the class SwitchToSlaveBranchThenCopyTest method newSwitchToSlaveSpy.
@SuppressWarnings("unchecked")
private SwitchToSlaveBranchThenCopy newSwitchToSlaveSpy(PageCache pageCacheMock, StoreCopyClient storeCopyClient) throws IOException {
ClusterMembers clusterMembers = mock(ClusterMembers.class);
ClusterMember master = mock(ClusterMember.class);
when(master.getStoreId()).thenReturn(storeId);
when(master.getHARole()).thenReturn(HighAvailabilityModeSwitcher.MASTER);
when(master.hasRole(eq(HighAvailabilityModeSwitcher.MASTER))).thenReturn(true);
when(master.getInstanceId()).thenReturn(new InstanceId(1));
when(clusterMembers.getMembers()).thenReturn(singletonList(master));
Dependencies resolver = new Dependencies();
resolver.satisfyDependencies(requestContextFactory, clusterMembers, mock(TransactionObligationFulfiller.class), mock(OnlineBackupKernelExtension.class), mock(IndexConfigStore.class), mock(TransactionCommittingResponseUnpacker.class), mock(DataSourceManager.class), mock(StoreLockerLifecycleAdapter.class), mock(FileSystemWatcherService.class));
NeoStoreDataSource dataSource = mock(NeoStoreDataSource.class);
when(dataSource.getStoreId()).thenReturn(storeId);
TransactionStats transactionCounters = mock(TransactionStats.class);
when(transactionCounters.getNumberOfActiveTransactions()).thenReturn(0L);
Response<HandshakeResult> response = mock(Response.class);
when(response.response()).thenReturn(new HandshakeResult(42, 2));
when(masterClient.handshake(anyLong(), any(StoreId.class))).thenReturn(response);
when(masterClient.getProtocolVersion()).thenReturn(MasterClient320.PROTOCOL_VERSION);
TransactionIdStore transactionIdStoreMock = mock(TransactionIdStore.class);
// note that the checksum (the second member of the array) is the same as the one in the handshake mock above
when(transactionIdStoreMock.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
MasterClientResolver masterClientResolver = mock(MasterClientResolver.class);
when(masterClientResolver.instantiate(anyString(), anyInt(), anyString(), any(Monitors.class), any(StoreId.class), any(LifeSupport.class))).thenReturn(masterClient);
return spy(new SwitchToSlaveBranchThenCopy(new File(""), NullLogService.getInstance(), configMock(), resolver, mock(HaIdGeneratorFactory.class), mock(DelegateInvocationHandler.class), mock(ClusterMemberAvailability.class), requestContextFactory, pullerFactory, masterClientResolver, mock(SwitchToSlave.Monitor.class), storeCopyClient, Suppliers.singleton(dataSource), Suppliers.singleton(transactionIdStoreMock), slave -> {
SlaveServer server = mock(SlaveServer.class);
InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved("localhost", 42);
when(server.getSocketAddress()).thenReturn(inetSocketAddress);
return server;
}, updatePuller, pageCacheMock, mock(Monitors.class), transactionCounters));
}
Aggregations