-
Notifications
You must be signed in to change notification settings - Fork 242
/
AbstractMassIndexerAgentClusterLinkTest.java
105 lines (82 loc) · 4.04 KB
/
AbstractMassIndexerAgentClusterLinkTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.mapper.orm.coordination.outboxpolling.event.impl;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.hibernate.search.engine.reporting.FailureHandler;
import org.hibernate.search.mapper.orm.coordination.outboxpolling.cfg.HibernateOrmMapperOutboxPollingSettings;
import org.hibernate.search.mapper.orm.coordination.outboxpolling.cluster.impl.Agent;
import org.hibernate.search.mapper.orm.coordination.outboxpolling.cluster.impl.AgentReference;
import org.hibernate.search.mapper.orm.coordination.outboxpolling.cluster.impl.AgentRepository;
import org.hibernate.search.mapper.orm.coordination.outboxpolling.cluster.impl.AgentState;
import org.hibernate.search.mapper.orm.coordination.outboxpolling.cluster.impl.AgentType;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
abstract class AbstractMassIndexerAgentClusterLinkTest {
static final Instant NOW = Instant.parse( "2021-11-21T14:30:00.000Z" );
static final Instant EARLIER = NOW.minus( 1, ChronoUnit.NANOS );
static final Instant LATER = NOW.plus( 1, ChronoUnit.NANOS );
static final Duration POLLING_INTERVAL = Duration.ofMillis(
HibernateOrmMapperOutboxPollingSettings.Defaults.COORDINATION_MASS_INDEXER_POLLING_INTERVAL );
static final Duration PULSE_INTERVAL = Duration.ofMillis(
HibernateOrmMapperOutboxPollingSettings.Defaults.COORDINATION_MASS_INDEXER_PULSE_INTERVAL );
static final Duration PULSE_EXPIRATION = Duration.ofMillis(
HibernateOrmMapperOutboxPollingSettings.Defaults.COORDINATION_MASS_INDEXER_PULSE_EXPIRATION );
static final long SELF_ID = 42L;
static final AgentReference SELF_REF = AgentReference.of( SELF_ID, "Self Agent Name" );
@Rule
public final MockitoRule mockito = MockitoJUnit.rule().strictness( Strictness.STRICT_STUBS );
@Mock
public FailureHandler failureHandlerMock;
@Mock
public Clock clockMock;
@Mock
public AgentRepository repositoryMock;
@Mock(stubOnly = true, lenient = true)
public AgentClusterLinkContext contextMock;
private final List<Object> allMocks = new ArrayList<>();
protected AgentRepositoryMockingHelper repositoryMockHelper;
@Before
public final void initMocks() {
repositoryMockHelper = new AgentRepositoryMockingHelper( repositoryMock );
Collections.addAll( allMocks, failureHandlerMock, clockMock, repositoryMock );
when( contextMock.agentRepository() ).thenReturn( repositoryMock );
// We're not interested in transaction control here
doNothing().when( contextMock ).commitAndBeginNewTransaction();
}
@After
public void verifyNoMoreInvocationsOnAllMocks() {
verifyNoMoreInteractions( allMocks.toArray() );
}
protected void defineSelfNotCreatedYet(OutboxPollingMassIndexerAgentClusterLink link) {
link.getAgentPersisterForTests().setSelfReferenceForTests( null );
repositoryMockHelper.defineSelfCreatedByPulse( SELF_ID );
}
protected void defineSelfCreatedAndStillPresent(OutboxPollingMassIndexerAgentClusterLink link,
AgentState state) {
link.getAgentPersisterForTests().setSelfReferenceForTests( SELF_REF );
Agent self = new Agent( AgentType.MASS_INDEXING, SELF_REF.name, NOW, state, null );
self.setId( SELF_ID );
repositoryMockHelper.defineSelfPreExisting( self );
}
protected final MassIndexerAgentClusterLinkPulseExpectations.InstructionsStep expect(OutboxPollingMassIndexerAgentClusterLink link) {
return MassIndexerAgentClusterLinkPulseExpectations.expect( repositoryMockHelper, link );
}
}