[TEST] fixed concurrency issue in IndicesRequestTests

This commit is contained in:
javanna 2014-08-21 10:43:41 +02:00 committed by Luca Cavanna
parent ea96359d82
commit 5709a11d23
1 changed files with 4 additions and 6 deletions

View File

@ -19,7 +19,6 @@
package org.elasticsearch.action; package org.elasticsearch.action;
import com.google.common.collect.Lists;
import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction; import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest;
@ -110,6 +109,7 @@ import org.junit.Test;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
@ -795,10 +795,6 @@ public class IndicesRequestTests extends ElasticsearchIntegrationTest {
} }
} }
private static void assertSameIndices(String[] indices, String... actions) {
assertSameIndices(indices, false, actions);
}
private static void assertSameIndicesOptionalRequests(String[] indices, String... actions) { private static void assertSameIndicesOptionalRequests(String[] indices, String... actions) {
assertSameIndices(indices, true, actions); assertSameIndices(indices, true, actions);
} }
@ -942,7 +938,9 @@ public class IndicesRequestTests extends ElasticsearchIntegrationTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void messageReceived(TransportRequest request, TransportChannel channel) throws Exception { public void messageReceived(TransportRequest request, TransportChannel channel) throws Exception {
if (actions.contains(action)) { if (actions.contains(action)) {
List<TransportRequest> transportRequests = requests.putIfAbsent(action, Lists.newArrayList(request)); List<TransportRequest> requestList = new CopyOnWriteArrayList<>();
requestList.add(request);
List<TransportRequest> transportRequests = requests.putIfAbsent(action, requestList);
if (transportRequests != null) { if (transportRequests != null) {
transportRequests.add(request); transportRequests.add(request);
} }