Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ plugins {
id 'lifecycle-base'
id 'opensearch.docker-support'
id 'opensearch.global-build-info'
id "com.diffplug.spotless" version "6.25.0" apply false
id "com.diffplug.spotless" version "8.0.0" apply false
id "org.gradle.test-retry" version "1.6.2" apply false
id "test-report-aggregation"
id 'jacoco-report-aggregation'
Expand Down
8 changes: 1 addition & 7 deletions gradle/formatting.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ allprojects {
target '**/*.java'

removeUnusedImports()
forbidWildcardImports()
importOrder(
'de.thetaphi',
'com.carrotsearch',
Expand All @@ -85,13 +86,6 @@ allprojects {
trimTrailingWhitespace()
endWithNewline()

custom 'Refuse wildcard imports', {
// Wildcard imports can't be resolved; fail the build
if (it =~ /\s+import .*\*;/) {
throw new AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.")
}
}

// See DEVELOPER_GUIDE.md for details of when to enable this.
if (System.getProperty('spotless.paddedcell') != null) {
paddedCell()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ public void setUp() throws Exception {
}

public void testResolveSingleIntersection() {
when(attr1.findAttributeMatches(extractor1, store1)).thenReturn(Arrays.asList(
new MatchLabel<>("a", 0.9f),
new MatchLabel<>("b", 0.8f)
));
when(attr2.findAttributeMatches(extractor2, store2)).thenReturn(Arrays.asList(
new MatchLabel<>("a", 0.95f),
new MatchLabel<>("c", 0.7f)
));
when(attr1.findAttributeMatches(extractor1, store1)).thenReturn(
Arrays.asList(new MatchLabel<>("a", 0.9f), new MatchLabel<>("b", 0.8f))
);
when(attr2.findAttributeMatches(extractor2, store2)).thenReturn(
Arrays.asList(new MatchLabel<>("a", 0.95f), new MatchLabel<>("c", 0.7f))
);

FeatureValueResolver resolver = new FeatureValueResolver(storeFactory, Arrays.asList(extractor1, extractor2));
Optional<String> result = resolver.resolve();
Expand All @@ -66,44 +64,34 @@ public void testResolveSingleIntersection() {
}

public void testResolveEmptyIntersection() {
when(attr1.findAttributeMatches(extractor1, store1)).thenReturn(Arrays.asList(
new MatchLabel<>("a", 0.9f)
));
when(attr2.findAttributeMatches(extractor2, store2)).thenReturn(Arrays.asList(
new MatchLabel<>("b", 0.8f)
));
when(attr1.findAttributeMatches(extractor1, store1)).thenReturn(Arrays.asList(new MatchLabel<>("a", 0.9f)));
when(attr2.findAttributeMatches(extractor2, store2)).thenReturn(Arrays.asList(new MatchLabel<>("b", 0.8f)));

FeatureValueResolver resolver = new FeatureValueResolver(storeFactory, Arrays.asList(extractor1, extractor2));
Optional<String> result = resolver.resolve();
assertFalse(result.isPresent());
}

public void testResolveTieBreakingWithoutResult() {
when(attr1.findAttributeMatches(extractor1, store1)).thenReturn(Arrays.asList(
new MatchLabel<>("a", 0.9f),
new MatchLabel<>("b", 0.9f),
new MatchLabel<>("c", 0.7f)
));
when(attr2.findAttributeMatches(extractor2, store2)).thenReturn(Arrays.asList(
new MatchLabel<>("a", 0.95f),
new MatchLabel<>("b", 0.95f)
));
when(attr1.findAttributeMatches(extractor1, store1)).thenReturn(
Arrays.asList(new MatchLabel<>("a", 0.9f), new MatchLabel<>("b", 0.9f), new MatchLabel<>("c", 0.7f))
);
when(attr2.findAttributeMatches(extractor2, store2)).thenReturn(
Arrays.asList(new MatchLabel<>("a", 0.95f), new MatchLabel<>("b", 0.95f))
);

FeatureValueResolver resolver = new FeatureValueResolver(storeFactory, Arrays.asList(extractor1, extractor2));
Optional<String> result = resolver.resolve();
assertFalse(result.isPresent());
}

public void testResolveTieBreaking() {
when(attr1.findAttributeMatches(extractor1, store1)).thenReturn(Arrays.asList(
new MatchLabel<>("a", 0.9f),
new MatchLabel<>("b", 0.9f),
new MatchLabel<>("c", 0.7f)
));
when(attr2.findAttributeMatches(extractor2, store2)).thenReturn(Arrays.asList(
new MatchLabel<>("b", 0.95f),
new MatchLabel<>("a", 0.9f)
));
when(attr1.findAttributeMatches(extractor1, store1)).thenReturn(
Arrays.asList(new MatchLabel<>("a", 0.9f), new MatchLabel<>("b", 0.9f), new MatchLabel<>("c", 0.7f))
);
when(attr2.findAttributeMatches(extractor2, store2)).thenReturn(
Arrays.asList(new MatchLabel<>("b", 0.95f), new MatchLabel<>("a", 0.9f))
);

FeatureValueResolver resolver = new FeatureValueResolver(storeFactory, Arrays.asList(extractor1, extractor2));
Optional<String> result = resolver.resolve();
Expand All @@ -112,9 +100,7 @@ public void testResolveTieBreaking() {
}

public void testResolveSingleExtractor() {
when(attr1.findAttributeMatches(extractor1, store1)).thenReturn(Arrays.asList(
new MatchLabel<>("x", 1.0f)
));
when(attr1.findAttributeMatches(extractor1, store1)).thenReturn(Arrays.asList(new MatchLabel<>("x", 1.0f)));

FeatureValueResolver resolver = new FeatureValueResolver(storeFactory, Collections.singletonList(extractor1));
Optional<String> result = resolver.resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,9 @@ public void testGetFlightInfo_LocationNotFound() {
}

public void testGetFlightInfo_SchemaError() {
when(streamManager.getStreamProducer(any(FlightStreamTicket.class)))
.thenReturn(Optional.of(FlightStreamManager.StreamProducerHolder.create(streamProducer, allocator)));
when(streamManager.getStreamProducer(any(FlightStreamTicket.class))).thenReturn(
Optional.of(FlightStreamManager.StreamProducerHolder.create(streamProducer, allocator))
);
Location location = Location.forGrpcInsecure("localhost", 8815);
when(flightClientManager.getFlightClientLocation(LOCAL_NODE_ID)).thenReturn(Optional.of(location));
when(streamProducer.createRoot(allocator)).thenReturn(mock(VectorSchemaRoot.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void tearDown() throws Exception {
public void testNext_ReturnsTrue_WhenFlightStreamHasNext() throws Exception {
when(mockFlightStream.next()).thenReturn(true);
assertTrue(iterator.next());
assert(mockFlightStream).next();
assert (mockFlightStream).next();
}

public void testNext_ReturnsFalse_WhenFlightStreamHasNoNext() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,7 @@ public void testFileCacheException() {
PruneFileCacheRequest globalRequest = new PruneFileCacheRequest();
TransportPruneFileCacheAction.NodeRequest nodeRequest = new TransportPruneFileCacheAction.NodeRequest(globalRequest);

RuntimeException exception = expectThrows(
RuntimeException.class,
() -> action.nodeOperation(nodeRequest)
);
RuntimeException exception = expectThrows(RuntimeException.class, () -> action.nodeOperation(nodeRequest));

assertTrue("Exception should contain node ID", exception.getMessage().contains("node"));
assertTrue("Exception should mention failure", exception.getMessage().contains("failed"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,7 @@ public void testDeleteStaleIndexRoutingPathsThrowsIOException() throws IOExcepti
doThrow(new IOException("test exception")).when(blobContainer).deleteBlobsIgnoringIfNotExists(Mockito.anyList());

remoteRoutingTableService.doStart();
IOException thrown = assertThrows(IOException.class, () -> {
remoteRoutingTableService.deleteStaleIndexRoutingPaths(stalePaths);
});
IOException thrown = assertThrows(IOException.class, () -> { remoteRoutingTableService.deleteStaleIndexRoutingPaths(stalePaths); });
assertEquals("test exception", thrown.getMessage());
verify(blobContainer).deleteBlobsIgnoringIfNotExists(stalePaths);
}
Expand All @@ -814,9 +812,10 @@ public void testDeleteStaleIndexRoutingDiffPathsThrowsIOException() throws IOExc
doThrow(new IOException("test exception")).when(blobContainer).deleteBlobsIgnoringIfNotExists(Mockito.anyList());

remoteRoutingTableService.doStart();
IOException thrown = assertThrows(IOException.class, () -> {
remoteRoutingTableService.deleteStaleIndexRoutingDiffPaths(stalePaths);
});
IOException thrown = assertThrows(
IOException.class,
() -> { remoteRoutingTableService.deleteStaleIndexRoutingDiffPaths(stalePaths); }
);
assertEquals("test exception", thrown.getMessage());
verify(blobContainer).deleteBlobsIgnoringIfNotExists(stalePaths);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ public void testNodeValidatorWithHealthyResources() {
);
when(threadPool.stats()).thenReturn(stats);

AutoForceMergeManager autoForceMergeManager = clusterSetupWithNode(getConfiguredClusterSettings(true, true, Collections.emptyMap()), getNodeWithRoles(DATA_NODE_1, Set.of(DiscoveryNodeRole.DATA_ROLE)));
AutoForceMergeManager autoForceMergeManager = clusterSetupWithNode(
getConfiguredClusterSettings(true, true, Collections.emptyMap()),
getNodeWithRoles(DATA_NODE_1, Set.of(DiscoveryNodeRole.DATA_ROLE))
);
autoForceMergeManager.start();
assertTrue(autoForceMergeManager.getNodeValidator().validate().isAllowed());
autoForceMergeManager.close();
Expand All @@ -265,21 +268,25 @@ public void testNodeValidatorWithFeatureSwitch() {
when(cpu.getPercent()).thenReturn((short) 50);
when(jvm.getHeapUsedPercent()).thenReturn((short) 60);
ThreadPoolStats stats = new ThreadPoolStats(
Arrays.asList(new ThreadPoolStats.Stats.Builder().name(ThreadPool.Names.FORCE_MERGE)
.threads(1)
.queue(0)
.active(0)
.rejected(0)
.largest(1)
.completed(0)
.waitTimeNanos(0)
.parallelism(-1)
.build()
Arrays.asList(
new ThreadPoolStats.Stats.Builder().name(ThreadPool.Names.FORCE_MERGE)
.threads(1)
.queue(0)
.active(0)
.rejected(0)
.largest(1)
.completed(0)
.waitTimeNanos(0)
.parallelism(-1)
.build()
)
);
when(threadPool.stats()).thenReturn(stats);
Settings settings = getConfiguredClusterSettings(false, false, Collections.emptyMap());
AutoForceMergeManager autoForceMergeManager = clusterSetupWithNode(settings, getNodeWithRoles(DATA_NODE_1, Set.of(DiscoveryNodeRole.DATA_ROLE)));
AutoForceMergeManager autoForceMergeManager = clusterSetupWithNode(
settings,
getNodeWithRoles(DATA_NODE_1, Set.of(DiscoveryNodeRole.DATA_ROLE))
);
autoForceMergeManager.start();
assertFalse(autoForceMergeManager.getConfigurationValidator().validate().isAllowed());
assertNotEquals(Lifecycle.State.STARTED, ResourceTrackerProvider.resourceTrackers.cpuFiveMinute.lifecycleState());
Expand Down Expand Up @@ -327,22 +334,28 @@ public void testNodeValidatorWithHighCPU() {
public void testNodeValidatorWithHighDiskUsage() {
when(cpu.getPercent()).thenReturn((short) 50);
when(disk.getAvailable()).thenReturn(new ByteSizeValue(5));
AutoForceMergeManager autoForceMergeManager = clusterSetupWithNode(getConfiguredClusterSettings(true, true, Collections.emptyMap()), getNodeWithRoles(DATA_NODE_1, Set.of(DiscoveryNodeRole.DATA_ROLE)));
AutoForceMergeManager autoForceMergeManager = clusterSetupWithNode(
getConfiguredClusterSettings(true, true, Collections.emptyMap()),
getNodeWithRoles(DATA_NODE_1, Set.of(DiscoveryNodeRole.DATA_ROLE))
);
autoForceMergeManager.start();
assertFalse(autoForceMergeManager.getNodeValidator().validate().isAllowed());
autoForceMergeManager.close();
}

public void testNodeValidatorWithHighJVMUsage() {
when(cpu.getPercent()).thenReturn((short) 50);
AutoForceMergeManager autoForceMergeManager = clusterSetupWithNode(getConfiguredClusterSettings(true, true, Collections.emptyMap()), getNodeWithRoles(DATA_NODE_1, Set.of(DiscoveryNodeRole.DATA_ROLE)));
AutoForceMergeManager autoForceMergeManager = clusterSetupWithNode(
getConfiguredClusterSettings(true, true, Collections.emptyMap()),
getNodeWithRoles(DATA_NODE_1, Set.of(DiscoveryNodeRole.DATA_ROLE))
);
autoForceMergeManager.start();
when(jvm.getHeapUsedPercent()).thenReturn((short) 90);
assertFalse(autoForceMergeManager.getNodeValidator().validate().isAllowed());
for(int i = 0; i < 10; i++)
for (int i = 0; i < 10; i++)
ResourceTrackerProvider.resourceTrackers.jvmOneMinute.recordUsage(90);
assertFalse(autoForceMergeManager.getNodeValidator().validate().isAllowed());
for(int i = 0; i < 10; i++)
for (int i = 0; i < 10; i++)
ResourceTrackerProvider.resourceTrackers.jvmFiveMinute.recordUsage(90);
assertFalse(autoForceMergeManager.getNodeValidator().validate().isAllowed());
autoForceMergeManager.close();
Expand All @@ -366,7 +379,10 @@ public void testNodeValidatorWithInsufficientForceMergeThreads() {
)
);
when(threadPool.stats()).thenReturn(stats);
AutoForceMergeManager autoForceMergeManager = clusterSetupWithNode(getConfiguredClusterSettings(true, true, Collections.emptyMap()), getNodeWithRoles(DATA_NODE_1, Set.of(DiscoveryNodeRole.DATA_ROLE)));
AutoForceMergeManager autoForceMergeManager = clusterSetupWithNode(
getConfiguredClusterSettings(true, true, Collections.emptyMap()),
getNodeWithRoles(DATA_NODE_1, Set.of(DiscoveryNodeRole.DATA_ROLE))
);
autoForceMergeManager.start();
assertFalse(autoForceMergeManager.getNodeValidator().validate().isAllowed());
ThreadPoolStats emptyStats = new ThreadPoolStats(Collections.emptyList());
Expand Down Expand Up @@ -678,13 +694,7 @@ private AutoForceMergeManager clusterSetupWithNode(Settings settings, DiscoveryN
when(clusterService.getSettings()).thenReturn(settings);
when(clusterService.localNode()).thenReturn(node);

return new AutoForceMergeManager(
threadPool,
monitorService,
indicesService,
clusterService,
autoForceMergeMetrics
);
return new AutoForceMergeManager(threadPool, monitorService, indicesService, clusterService, autoForceMergeMetrics);
}

public void testMergesSkippedNoWarmNodesMetric() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,32 @@ public void test_buildWithNoStarTreeFields() throws IOException {
public void test_getStarTreeBuilder() throws IOException {
when(mapperService.getCompositeFieldTypes()).thenReturn(Set.of(starTreeFieldType));
StarTreesBuilder starTreesBuilder = new StarTreesBuilder(segmentWriteState, mapperService, new AtomicInteger());
StarTreeBuilder starTreeBuilder = starTreesBuilder.getStarTreeBuilder(metaOut, dataOut, starTreeField, segmentWriteState, mapperService);
StarTreeBuilder starTreeBuilder = starTreesBuilder.getStarTreeBuilder(
metaOut,
dataOut,
starTreeField,
segmentWriteState,
mapperService
);
assertTrue(starTreeBuilder instanceof OnHeapStarTreeBuilder);
}

public void test_getStarTreeBuilder_illegalArgument() throws IOException {
when(mapperService.getCompositeFieldTypes()).thenReturn(Set.of(starTreeFieldType));
StarTreeFieldConfiguration starTreeFieldConfiguration = new StarTreeFieldConfiguration(1, new HashSet<>(), StarTreeFieldConfiguration.StarTreeBuildMode.OFF_HEAP);
StarTreeFieldConfiguration starTreeFieldConfiguration = new StarTreeFieldConfiguration(
1,
new HashSet<>(),
StarTreeFieldConfiguration.StarTreeBuildMode.OFF_HEAP
);
StarTreeField starTreeField = new StarTreeField("star_tree", new ArrayList<>(), new ArrayList<>(), starTreeFieldConfiguration);
StarTreesBuilder starTreesBuilder = new StarTreesBuilder(segmentWriteState, mapperService, new AtomicInteger());
StarTreeBuilder starTreeBuilder = starTreesBuilder.getStarTreeBuilder(metaOut, dataOut, starTreeField, segmentWriteState, mapperService);
StarTreeBuilder starTreeBuilder = starTreesBuilder.getStarTreeBuilder(
metaOut,
dataOut,
starTreeField,
segmentWriteState,
mapperService
);
assertTrue(starTreeBuilder instanceof OffHeapStarTreeBuilder);
starTreeBuilder.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ public void testGetPrimaryTermGenerationUuid() {
}

public void testInitException() throws IOException {
when(remoteMetadataDirectory.listFilesByPrefixInLexicographicOrder(RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX, METADATA_FILES_TO_FETCH)).thenThrow(
new IOException("Error")
);
when(
remoteMetadataDirectory.listFilesByPrefixInLexicographicOrder(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
METADATA_FILES_TO_FETCH
)
).thenThrow(new IOException("Error"));

assertThrows(IOException.class, () -> remoteSegmentStoreDirectory.init());
}
Expand All @@ -155,9 +158,12 @@ public void testInitNoMetadataFile() throws IOException {
}

public void testInitMultipleMetadataFile() throws IOException {
when(remoteMetadataDirectory.listFilesByPrefixInLexicographicOrder(RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX, METADATA_FILES_TO_FETCH)).thenReturn(
List.of(metadataFilename, metadataFilenameDup)
);
when(
remoteMetadataDirectory.listFilesByPrefixInLexicographicOrder(
RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX,
METADATA_FILES_TO_FETCH
)
).thenReturn(List.of(metadataFilename, metadataFilenameDup));
assertThrows(IllegalStateException.class, () -> remoteSegmentStoreDirectory.init());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ public void testDeleteStaleCommitsPinnedTimestampMdFile() throws Exception {
)
).thenReturn(List.of(metadataFilename, metadataFilename2, metadataFilename3));

long pinnedTimestampMatchingMetadataFilename2 = RemoteSegmentStoreDirectory.MetadataFilenameUtils.getTimestamp(metadataFilename2) + 10;
long pinnedTimestampMatchingMetadataFilename2 = RemoteSegmentStoreDirectory.MetadataFilenameUtils.getTimestamp(metadataFilename2)
+ 10;
String blobName = "snapshot1__" + pinnedTimestampMatchingMetadataFilename2;
when(blobContainer.listBlobs()).thenReturn(Map.of(blobName, new PlainBlobMetadata(blobName, 100)));

Expand Down
Loading
Loading