Skip to content

Commit

Permalink
A couple more assertions and throws in error cases to appease SonarQu…
Browse files Browse the repository at this point in the history
…be's quality rules.

Signed-off-by: Greg Schohn <[email protected]>
  • Loading branch information
gregschohn committed Sep 25, 2024
1 parent e27072e commit 2b363e8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.opensearch.migrations.bulkload.common.http.ConnectionContext;
import org.opensearch.migrations.bulkload.common.http.HttpResponse;

import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -40,7 +41,8 @@ public ObjectNode getClusterData() {
)
.collectMap(Entry::getKey, Entry::getValue)
.block();


assert responses != null;
var globalMetadata = globalMetadataFromParts(responses);
log.atDebug()
.setMessage("Combined global metadata:\n{}")
Expand All @@ -49,11 +51,11 @@ public ObjectNode getClusterData() {
return globalMetadata;
}

private ObjectNode globalMetadataFromParts(Map<String, ObjectNode> templatesDetails) {
private ObjectNode globalMetadataFromParts(@NonNull Map<String, ObjectNode> templatesDetails) {
var rootNode = objectMapper.createObjectNode();

templatesDetails.forEach((name, json) -> {
if (json != null && json.size() != 0) {
if (json != null && !json.isEmpty()) {
var inner = objectMapper.createObjectNode().set(name, json);
rootNode.set(name, inner);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ private <T> Optional<Level> logActiveItems(
}
if (numOutput++ == 0) {
logger.accept(
getHigherLevel(levelForElementOp, Optional.of(Level.INFO)).get(),
getHigherLevel(levelForElementOp, Optional.of(Level.INFO))
.orElseThrow(IllegalStateException::new),
() -> "Oldest of " + totalItems + trailingGroupLabel
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public <T> TrackedFuture<String, T> addFutureForWork(final int index, FutureTran
"index (" + index + ")" + " must be > last processed item (" + currentOffset + ")"
);
}
for (int nextKey = Math.max(
currentOffset,
items.isEmpty() ? Integer.MIN_VALUE : items.lastKey() + 1
); nextKey <= index; ++nextKey) {
for (int nextKey = Math.max(currentOffset, items.isEmpty() ? Integer.MIN_VALUE : items.lastKey() + 1);
nextKey <= index;
++nextKey)
{
int finalNextKey = nextKey;
var signalFuture = items.isEmpty()
? new TextTrackedFuture<Void>(
Expand All @@ -108,6 +108,8 @@ public <T> TrackedFuture<String, T> addFutureForWork(final int index, FutureTran
}, () -> "cleaning up spent work for idx #" + finalNextKey);
items.put(nextKey, workItem);
}
assert workItem != null : "workItem wasn't set and the earlier checks didn't signal " +
"why there might have been an issue idx=" + index + " this=" + this;
}
return workItem.addWorkFuture(processor, index);
}
Expand Down

0 comments on commit 2b363e8

Please sign in to comment.