Skip to content

Commit 7dc1765

Browse files
committed
disable assertions since too many tests add/remove default project
1 parent 869a9e0 commit 7dc1765

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

server/src/main/java/org/elasticsearch/cluster/ClusterChangedEvent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,9 @@ private static ProjectsDelta calculateProjectDelta(Metadata previousMetadata, Me
363363
final Set<ProjectId> removed = Collections.unmodifiableSet(
364364
Sets.difference(previousMetadata.projects().keySet(), currentMetadata.projects().keySet())
365365
);
366-
assert added.contains(ProjectId.DEFAULT) == false;
367-
assert removed.contains(ProjectId.DEFAULT) == false;
366+
// TODO: Enable the following assertions once tests no longer add or remove default projects
367+
// assert added.contains(ProjectId.DEFAULT) == false;
368+
// assert removed.contains(ProjectId.DEFAULT) == false;
368369
return new ProjectsDelta(added, removed);
369370
}
370371

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/async/AsyncTaskMaintenanceServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testStartStopDuringClusterChanges() {
6767
final String localNodeId = randomIdentifier();
6868
final String alternateNodeId = randomIdentifier();
6969

70-
final Metadata.Builder metadataBuilder = Metadata.builder(Metadata.EMPTY_METADATA);
70+
final Metadata.Builder metadataBuilder = Metadata.builder();
7171
final GlobalRoutingTable.Builder grtBuilder = GlobalRoutingTable.builder();
7272

7373
final ProjectId p1 = ProjectId.fromId("p1");

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/QueryableBuiltInRolesSynchronizerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ public void testSecurityIndexDeleted() {
330330

331331
synchronizer.clusterChanged(event(currentClusterState, previousClusterState));
332332

333-
verify(previousClusterState, times(2)).metadata();
334-
verify(currentClusterState, times(2)).metadata();
333+
verify(previousClusterState, times(1)).metadata();
334+
verify(currentClusterState, times(1)).metadata();
335335
verifyNoMoreInteractions(nativeRolesStore, featureService, taskQueue, reservedRolesProvider, threadPool, clusterService);
336336
}
337337

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
import static org.hamcrest.Matchers.not;
9696
import static org.hamcrest.Matchers.notNullValue;
9797
import static org.hamcrest.Matchers.nullValue;
98-
import static org.hamcrest.Matchers.oneOf;
9998
import static org.mockito.ArgumentMatchers.any;
10099
import static org.mockito.ArgumentMatchers.anyString;
101100
import static org.mockito.ArgumentMatchers.eq;
@@ -316,13 +315,10 @@ public void testIndexHealthChangeListeners() {
316315
final AtomicReference<IndexState> previousState = new AtomicReference<>();
317316
final AtomicReference<IndexState> currentState = new AtomicReference<>();
318317
final TriConsumer<ProjectId, IndexState, IndexState> listener = (projId, prevState, state) -> {
319-
assertThat(projId, oneOf(ProjectId.DEFAULT, projectId));
320-
if (projId.equals(projectId)) {
321-
projectIdRef.set(projId);
322-
previousState.set(prevState);
323-
currentState.set(state);
324-
listenerCalled.set(true);
325-
}
318+
projectIdRef.set(projId);
319+
previousState.set(prevState);
320+
currentState.set(state);
321+
listenerCalled.set(true);
326322
};
327323
manager.addStateListener(listener);
328324

@@ -577,11 +573,9 @@ public void testIndexOutOfDateListeners() {
577573
manager.clusterChanged(new ClusterChangedEvent("test-event", clusterState, clusterState));
578574
AtomicBoolean upToDateChanged = new AtomicBoolean();
579575
manager.addStateListener((projId, prev, current) -> {
580-
assertThat(projId, oneOf(ProjectId.DEFAULT, projectId));
581-
if (projId.equals(projectId)) {
582-
listenerCalled.set(true);
583-
upToDateChanged.set(prev.isIndexUpToDate != current.isIndexUpToDate);
584-
}
576+
assertThat(projId, equalTo(projectId));
577+
listenerCalled.set(true);
578+
upToDateChanged.set(prev.isIndexUpToDate != current.isIndexUpToDate);
585579
});
586580
assertThat(manager.getProject(projectId).isIndexUpToDate(), is(true));
587581

@@ -785,7 +779,7 @@ public void testGetRoleMappingsCleanupMigrationStatus() {
785779
metadataBuilder.put(builder.build());
786780

787781
// No role mappings in cluster state yet
788-
metadataBuilder.getProject(projectId).putCustom(RoleMappingMetadata.TYPE, new RoleMappingMetadata(Set.of()));
782+
metadataBuilder.putCustom(RoleMappingMetadata.TYPE, new RoleMappingMetadata(Set.of()));
789783

790784
assertThat(
791785
SecurityIndexManager.getRoleMappingsCleanupMigrationStatus(
@@ -809,13 +803,10 @@ public void testGetRoleMappingsCleanupMigrationStatus() {
809803
metadataBuilder.put(builder.build());
810804

811805
// Role mappings in cluster state with fallback name
812-
metadataBuilder.getProject(projectId)
813-
.putCustom(
814-
RoleMappingMetadata.TYPE,
815-
new RoleMappingMetadata(
816-
Set.of(new ExpressionRoleMapping(RoleMappingMetadata.FALLBACK_NAME, null, null, null, null, true))
817-
)
818-
);
806+
metadataBuilder.putCustom(
807+
RoleMappingMetadata.TYPE,
808+
new RoleMappingMetadata(Set.of(new ExpressionRoleMapping(RoleMappingMetadata.FALLBACK_NAME, null, null, null, null, true)))
809+
);
819810

820811
assertThat(
821812
SecurityIndexManager.getRoleMappingsCleanupMigrationStatus(
@@ -839,11 +830,10 @@ public void testGetRoleMappingsCleanupMigrationStatus() {
839830
metadataBuilder.put(builder.build());
840831

841832
// Role mappings in cluster state
842-
metadataBuilder.getProject(projectId)
843-
.putCustom(
844-
RoleMappingMetadata.TYPE,
845-
new RoleMappingMetadata(Set.of(new ExpressionRoleMapping("role_mapping_1", null, null, null, null, true)))
846-
);
833+
metadataBuilder.putCustom(
834+
RoleMappingMetadata.TYPE,
835+
new RoleMappingMetadata(Set.of(new ExpressionRoleMapping("role_mapping_1", null, null, null, null, true)))
836+
);
847837

848838
assertThat(
849839
SecurityIndexManager.getRoleMappingsCleanupMigrationStatus(
@@ -1100,7 +1090,7 @@ private ClusterState.Builder createClusterState(
11001090
String mappings,
11011091
Map<String, SystemIndexDescriptor.MappingsVersion> compatibilityVersions
11021092
) {
1103-
final Metadata metadata = Metadata.builder(Metadata.EMPTY_METADATA)
1093+
final Metadata metadata = Metadata.builder()
11041094
.put(createProjectMetadata(projectId, indexName, aliasName, format, state, mappings))
11051095
.build();
11061096
final GlobalRoutingTable routingTable = GlobalRoutingTableTestHelper.buildRoutingTable(metadata, RoutingTable.Builder::addAsNew);
@@ -1151,10 +1141,7 @@ public static ClusterState state(ProjectId projectId) {
11511141
.masterNodeId("1")
11521142
.localNodeId("1")
11531143
.build();
1154-
final Metadata metadata = Metadata.builder(Metadata.EMPTY_METADATA)
1155-
.put(ProjectMetadata.builder(projectId))
1156-
.generateClusterUuidIfNeeded()
1157-
.build();
1144+
final Metadata metadata = Metadata.builder().put(ProjectMetadata.builder(projectId)).generateClusterUuidIfNeeded().build();
11581145
return ClusterState.builder(CLUSTER_NAME).nodes(nodes).metadata(metadata).build();
11591146
}
11601147

0 commit comments

Comments
 (0)