Skip to content

Commit

Permalink
Remove commons-collections 3.2.2
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Pleskach <[email protected]>
  • Loading branch information
willyborankin committed Jul 2, 2023
1 parent 9a72355 commit e3b5f98
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 58 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ dependencies {
runtimeOnly 'org.opensaml:opensaml-soap-impl:3.4.5'
implementation 'org.opensaml:opensaml-storage-api:3.4.5'
implementation 'commons-lang:commons-lang:2.4'
implementation 'commons-collections:commons-collections:3.2.2'
implementation 'com.jayway.jsonpath:json-path:2.4.0'
implementation 'net.minidev:json-smart:2.4.10'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.10.8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,25 @@
*/
package org.opensearch.test.framework.log;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.BufferUtils;
import org.apache.commons.collections.buffer.CircularFifoBuffer;
import com.google.common.collect.EvictingQueue;
import com.google.common.collect.Queues;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Core;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import static org.opensearch.test.framework.log.LogCapturingAppender.PLUGIN_NAME;

/**
Expand All @@ -56,21 +52,15 @@ public class LogCapturingAppender extends AbstractAppender {
/**
* Buffer for captured log messages
*/
private static final Buffer messages = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(MAX_SIZE));
private static final Queue<LogMessage> messages = Queues.synchronizedQueue(EvictingQueue.create(MAX_SIZE));

/**
* Log messages are stored in buffer {@link #messages} only for classes which are added to the {@link #activeLoggers} set.
*/
private static final Set<String> activeLoggers = Collections.synchronizedSet(new HashSet<>());
private static final Set<String> activeLoggers = ConcurrentHashMap.newKeySet();

protected LogCapturingAppender(
String name,
Filter filter,
Layout<? extends Serializable> layout,
boolean ignoreExceptions,
Property[] properties
) {
super(name, filter, layout, ignoreExceptions, properties);
protected LogCapturingAppender(String name) {
super(name, null, null, true, Property.EMPTY_ARRAY);
}

/**
Expand All @@ -82,7 +72,7 @@ protected LogCapturingAppender(
public static LogCapturingAppender createAppender(
@PluginAttribute(value = "name", defaultString = "logCapturingAppender") String name
) {
return new LogCapturingAppender(name, null, null, true, Property.EMPTY_ARRAY);
return new LogCapturingAppender(name);
}

/**
Expand All @@ -91,10 +81,7 @@ public static LogCapturingAppender createAppender(
*/
@Override
public void append(LogEvent event) {
String loggerName = event.getLoggerName();
boolean loggable = activeLoggers.contains(loggerName);
if (loggable) {
event.getThrown();
if (activeLoggers.contains(event.getLoggerName())) {
messages.add(new LogMessage(event.getMessage().getFormattedMessage(), event.getThrown()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.util.stream.Collectors;

import com.google.common.collect.ImmutableSet;
import org.apache.commons.collections.keyvalue.MultiKey;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.greenrobot.eventbus.Subscribe;
Expand Down Expand Up @@ -156,17 +155,14 @@ private class ResolvedIndicesProvider implements IndicesProvider {
private final ImmutableSet.Builder<String> allIndices;
private final ImmutableSet.Builder<String> originalRequested;
private final ImmutableSet.Builder<String> remoteIndices;
// set of previously resolved index requests to avoid resolving
// the same index more than once while processing bulk requests
private final Set<MultiKey> alreadyResolved;

private final String name;

ResolvedIndicesProvider(Object request) {
aliases = ImmutableSet.builder();
allIndices = ImmutableSet.builder();
originalRequested = ImmutableSet.builder();
remoteIndices = ImmutableSet.builder();
alreadyResolved = new HashSet<>();
name = request.getClass().getSimpleName();
}

Expand Down Expand Up @@ -336,18 +332,18 @@ public String[] provide(String[] original, Object localRequest, boolean supports
|| localRequest instanceof SearchRequest
|| localRequest instanceof ResolveIndexAction.Request;
// skip the whole thing if we have seen this exact resolveIndexPatterns request
if (alreadyResolved.add(
new MultiKey(indicesOptions, enableCrossClusterResolution, (original != null) ? new MultiKey(original, false) : null)
)) {
resolveIndexPatterns(localRequest.getClass().getSimpleName(), indicesOptions, enableCrossClusterResolution, original);
}
resolveIndexPatterns(localRequest.getClass().getSimpleName(), indicesOptions, enableCrossClusterResolution, original);
return IndicesProvider.NOOP;
}

Resolved resolved(IndicesOptions indicesOptions) {
final Resolved resolved = alreadyResolved.isEmpty()
? Resolved._LOCAL_ALL
: new Resolved(aliases.build(), allIndices.build(), originalRequested.build(), remoteIndices.build(), indicesOptions);
final Resolved resolved = new Resolved(
aliases.build(),
allIndices.build(),
originalRequested.build(),
remoteIndices.build(),
indicesOptions
);

if (log.isTraceEnabled()) {
log.trace("Finally resolved for {}: {}", name, resolved);
Expand All @@ -359,22 +355,18 @@ Resolved resolved(IndicesOptions indicesOptions) {

// dnfof
public boolean replace(final TransportRequest request, boolean retainMode, String... replacements) {
return getOrReplaceAllIndices(request, new IndicesProvider() {

@Override
public String[] provide(String[] original, Object request, boolean supportsReplace) {
if (supportsReplace) {
if (retainMode && !isAllWithNoRemote(original)) {
final Resolved resolved = resolveRequest(request);
final List<String> retained = WildcardMatcher.from(resolved.getAllIndices())
.getMatchAny(replacements, Collectors.toList());
retained.addAll(resolved.getRemoteIndices());
return retained.toArray(new String[0]);
}
return replacements;
} else {
return NOOP;
return getOrReplaceAllIndices(request, (original, request1, supportsReplace) -> {
if (supportsReplace) {
if (retainMode && !isAllWithNoRemote(original)) {
final Resolved resolved = resolveRequest(request1);
final List<String> retained = WildcardMatcher.from(resolved.getAllIndices())
.getMatchAny(replacements, Collectors.toList());
retained.addAll(resolved.getRemoteIndices());
return retained.toArray(new String[0]);
}
return replacements;
} else {
return IndicesProvider.NOOP;
}
}, false);
}
Expand Down

0 comments on commit e3b5f98

Please sign in to comment.