use of org.neo4j.kernel.AvailabilityGuard in project neo4j by neo4j.
the class TransactionStateMachineSPITest method throwsWhenTxAwaitDurationExpires.
@Test
public void throwsWhenTxAwaitDurationExpires() throws Exception {
long lastClosedTransactionId = 100;
TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
Duration txAwaitDuration = Duration.ofSeconds(42);
FakeClock clock = new FakeClock();
AvailabilityGuard availabilityGuard = spy(new AvailabilityGuard(clock, NullLog.getInstance()));
when(availabilityGuard.isAvailable()).then(invocation -> {
boolean available = (boolean) invocation.callRealMethod();
clock.forward(txAwaitDuration.getSeconds() + 1, SECONDS);
return available;
});
TransactionStateMachineSPI txSpi = createTxSpi(txIdStore, txAwaitDuration, availabilityGuard, clock);
Future<Void> result = otherThread.execute(state -> {
txSpi.awaitUpToDate(lastClosedTransactionId + 42);
return null;
});
try {
result.get(20, SECONDS);
} catch (Exception e) {
assertThat(e, instanceOf(ExecutionException.class));
assertThat(e.getCause(), instanceOf(TransactionFailureException.class));
}
}
use of org.neo4j.kernel.AvailabilityGuard in project neo4j by neo4j.
the class NeoStoreDataSourceRule method getDataSource.
public NeoStoreDataSource getDataSource(File storeDir, FileSystemAbstraction fs, IdGeneratorFactory idGeneratorFactory, IdTypeConfigurationProvider idConfigurationProvider, PageCache pageCache, Config config, DatabaseHealth databaseHealth, LogService logService) {
if (dataSource != null) {
dataSource.stop();
dataSource.shutdown();
}
StatementLocksFactory locksFactory = mock(StatementLocksFactory.class);
StatementLocks statementLocks = mock(StatementLocks.class);
Locks.Client locks = mock(Locks.Client.class);
when(statementLocks.optimistic()).thenReturn(locks);
when(statementLocks.pessimistic()).thenReturn(locks);
when(locksFactory.newInstance()).thenReturn(statementLocks);
JobScheduler jobScheduler = mock(JobScheduler.class, RETURNS_MOCKS);
Monitors monitors = new Monitors();
LabelScanStoreProvider labelScanStoreProvider = nativeLabelScanStoreProvider(storeDir, fs, pageCache, config, logService);
SystemNanoClock clock = Clocks.nanoClock();
dataSource = new NeoStoreDataSource(storeDir, config, idGeneratorFactory, IdReuseEligibility.ALWAYS, idConfigurationProvider, logService, mock(JobScheduler.class, RETURNS_MOCKS), mock(TokenNameLookup.class), dependencyResolverForNoIndexProvider(labelScanStoreProvider), mock(PropertyKeyTokenHolder.class), mock(LabelTokenHolder.class), mock(RelationshipTypeTokenHolder.class), locksFactory, mock(SchemaWriteGuard.class), mock(TransactionEventHandlers.class), IndexingService.NO_MONITOR, fs, mock(TransactionMonitor.class), databaseHealth, mock(PhysicalLogFile.Monitor.class), TransactionHeaderInformationFactory.DEFAULT, new StartupStatisticsProvider(), null, new CommunityCommitProcessFactory(), mock(InternalAutoIndexing.class), pageCache, new StandardConstraintSemantics(), monitors, new Tracers("null", NullLog.getInstance(), monitors, jobScheduler), mock(Procedures.class), IOLimiter.unlimited(), new AvailabilityGuard(clock, NullLog.getInstance()), clock, new CanWrite(), new StoreCopyCheckPointMutex());
return dataSource;
}
use of org.neo4j.kernel.AvailabilityGuard in project neo4j by neo4j.
the class BoltFactoryImpl method start.
@Override
public void start() throws Throwable {
DependencyResolver dependencyResolver = gds.getDependencyResolver();
queryExecutionEngine = dependencyResolver.resolveDependency(QueryExecutionEngine.class);
queryService = dependencyResolver.resolveDependency(GraphDatabaseQueryService.class);
transactionIdStore = dependencyResolver.resolveDependency(TransactionIdStore.class);
availabilityGuard = dependencyResolver.resolveDependency(AvailabilityGuard.class);
}
use of org.neo4j.kernel.AvailabilityGuard in project neo4j by neo4j.
the class SlaveLocksClientTest method setUp.
@Before
public void setUp() throws Exception {
master = mock(Master.class);
availabilityGuard = new AvailabilityGuard(Clocks.fakeClock(), getInstance());
lockManager = new CommunityLockManger(Config.defaults(), Clocks.systemClock());
local = spy(lockManager.newClient());
logProvider = new AssertableLogProvider();
LockResult lockResultOk = new LockResult(LockStatus.OK_LOCKED);
TransactionStreamResponse<LockResult> responseOk = new TransactionStreamResponse<>(lockResultOk, null, TransactionStream.EMPTY, ResourceReleaser.NO_OP);
whenMasterAcquireShared().thenReturn(responseOk);
whenMasterAcquireExclusive().thenReturn(responseOk);
client = new SlaveLocksClient(master, local, lockManager, mock(RequestContextFactory.class), availabilityGuard, logProvider);
}
use of org.neo4j.kernel.AvailabilityGuard in project neo4j by neo4j.
the class HighAvailabilityMemberStateMachineTest method whenInMasterStateLosingQuorumFromThreeInstancesShouldGoToPending.
@Test
public void whenInMasterStateLosingQuorumFromThreeInstancesShouldGoToPending() throws Throwable {
// Given
InstanceId me = new InstanceId(1);
InstanceId other1 = new InstanceId(2);
InstanceId other2 = new InstanceId(3);
HighAvailabilityMemberContext context = new SimpleHighAvailabilityMemberContext(me, false);
AvailabilityGuard guard = mock(AvailabilityGuard.class);
List<InstanceId> otherInstances = new LinkedList();
otherInstances.add(other1);
otherInstances.add(other2);
ObservedClusterMembers members = mockClusterMembers(me, emptyList(), otherInstances);
ClusterMemberEvents events = mock(ClusterMemberEvents.class);
ClusterMemberListenerContainer memberListenerContainer = mockAddClusterMemberListener(events);
HighAvailabilityMemberStateMachine stateMachine = buildMockedStateMachine(context, events, members, guard);
stateMachine.init();
ClusterMemberListener memberListener = memberListenerContainer.get();
HAStateChangeListener probe = new HAStateChangeListener();
stateMachine.addHighAvailabilityMemberListener(probe);
// Send it to MASTER
memberListener.coordinatorIsElected(me);
memberListener.memberIsAvailable(MASTER, me, URI.create("ha://whatever"), StoreId.DEFAULT);
assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.MASTER));
// When
memberListener.memberIsFailed(new InstanceId(2));
// Then
assertThat(stateMachine.getCurrentState(), equalTo(HighAvailabilityMemberState.PENDING));
assertThat(probe.instanceStops, is(false));
assertThat(probe.instanceDetached, is(true));
verify(guard, times(1)).require(any(AvailabilityRequirement.class));
}
Aggregations