-
Notifications
You must be signed in to change notification settings - Fork 242
/
OutboxPollingAutomaticIndexingStaticShardingIncompatibleConfigurationIT.java
170 lines (140 loc) · 6.39 KB
/
OutboxPollingAutomaticIndexingStaticShardingIncompatibleConfigurationIT.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* 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.integrationtest.mapper.orm.coordination.outboxpolling.automaticindexing;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import java.util.Collections;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.cfg.Environment;
import org.hibernate.search.engine.backend.analysis.AnalyzerNames;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.CoordinationStrategyExpectations;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper;
import org.hibernate.search.util.impl.test.annotation.TestForIssue;
import org.hibernate.search.util.impl.test.rule.ExpectedLog4jLog;
import org.junit.Rule;
import org.junit.Test;
/**
* Test for static sharding where some nodes are configured in an incompatible way.
*/
@TestForIssue(jiraKey = "HSEARCH-4140")
public class OutboxPollingAutomaticIndexingStaticShardingIncompatibleConfigurationIT {
@Rule
public BackendMock backendMock = new BackendMock();
@Rule
public OrmSetupHelper ormSetupHelper = OrmSetupHelper.withBackendMock( backendMock )
.coordinationStrategy( CoordinationStrategyExpectations.outboxPolling() );
@Rule
public ExpectedLog4jLog logged = ExpectedLog4jLog.create();
private void setup(String hbm2ddlAction, TestFailureHandler failureHandler, int totalShardCount, List<Integer> assignedShardIndices) {
backendMock.expectSchema( IndexedEntity.NAME, b -> b
.field( "text", String.class, f -> f.analyzerName( AnalyzerNames.DEFAULT ) )
);
OrmSetupHelper.SetupContext context = ormSetupHelper.start()
.withProperty( Environment.HBM2DDL_AUTO, hbm2ddlAction )
.withProperty( "hibernate.search.background_failure_handler", failureHandler )
.withProperty( "hibernate.search.coordination.event_processor.shards.total_count", totalShardCount )
.withProperty( "hibernate.search.coordination.event_processor.shards.assigned", assignedShardIndices );
context.setup( IndexedEntity.class );
}
@Test
public void conflictingTotalShardCount() throws InterruptedException {
TestFailureHandler sessionFactory1FailureHandler = new TestFailureHandler();
TestFailureHandler sessionFactory2FailureHandler = new TestFailureHandler();
setup( "create-drop", sessionFactory1FailureHandler, 1, Collections.singletonList( 0 ) );
setup( "none", sessionFactory2FailureHandler, 2, Collections.singletonList( 1 ) );
backendMock.verifyExpectationsMet();
await().untilAsserted( () -> {
assertThat( sessionFactory1FailureHandler.genericFailures ).isNotEmpty();
assertThat( sessionFactory2FailureHandler.genericFailures ).isNotEmpty();
} );
String[] expectedContent = new String[] {
"is statically assigned to shard ",
"this conflicts with agent '",
"' which expects ", " shards.",
"This can be a temporary situation caused by some application instances being forcibly stopped and replacements being spun up",
"consider adjusting the configuration or switching to dynamic sharding.",
"Registered agents:"
};
assertThat( sessionFactory1FailureHandler.genericFailures )
.allSatisfy( failureContext -> {
assertThat( failureContext.throwable() )
.hasMessageContainingAll( expectedContent );
} );
assertThat( sessionFactory2FailureHandler.genericFailures )
.allSatisfy( failureContext -> {
assertThat( failureContext.throwable() )
.hasMessageContainingAll( expectedContent );
} );
// Also check that we don't flood the logs because of repeated pulses every few milliseconds
Thread.sleep( 1000 );
assertThat( sessionFactory1FailureHandler.genericFailures ).hasSizeLessThan( 3 );
assertThat( sessionFactory2FailureHandler.genericFailures ).hasSizeLessThan( 3 );
}
@Test
public void conflictingAssignedShardIndex() throws InterruptedException {
TestFailureHandler sessionFactory1FailureHandler = new TestFailureHandler();
TestFailureHandler sessionFactory2FailureHandler = new TestFailureHandler();
setup( "create-drop", sessionFactory1FailureHandler, 2, Collections.singletonList( 0 ) );
setup( "none", sessionFactory2FailureHandler, 2, Collections.singletonList( 0 ) );
backendMock.verifyExpectationsMet();
await().untilAsserted( () -> {
assertThat( sessionFactory1FailureHandler.genericFailures ).isNotEmpty();
assertThat( sessionFactory2FailureHandler.genericFailures ).isNotEmpty();
} );
String[] expectedContent = new String[] {
"is statically assigned to shard ",
"this conflicts with agent '",
"' which is also assigned to that shard.",
"This can be a temporary situation caused by some application instances being forcibly stopped and replacements being spun up",
"consider adjusting the configuration or switching to dynamic sharding.",
"Registered agents:"
};
assertThat( sessionFactory1FailureHandler.genericFailures )
.allSatisfy( failureContext -> {
assertThat( failureContext.throwable() )
.hasMessageContainingAll( expectedContent );
} );
assertThat( sessionFactory2FailureHandler.genericFailures )
.allSatisfy( failureContext -> {
assertThat( failureContext.throwable() )
.hasMessageContainingAll( expectedContent );
} );
// Also check that we don't flood the logs because of repeated pulses every few milliseconds
Thread.sleep( 1000 );
assertThat( sessionFactory1FailureHandler.genericFailures ).hasSizeLessThan( 3 );
assertThat( sessionFactory2FailureHandler.genericFailures ).hasSizeLessThan( 3 );
}
@Entity(name = IndexedEntity.NAME)
@Indexed
public static class IndexedEntity {
static final String NAME = "IndexedEntity";
@Id
private Integer id;
@FullTextField
private String text;
public IndexedEntity() {
}
public IndexedEntity(Integer id, String text) {
this.id = id;
this.text = text;
}
public Integer getId() {
return id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
}