mirror of https://github.com/apache/lucene.git
SOLR-8995: Replace anonymous implementations of SAM interfaces with Lambdas
This commit is contained in:
parent
50c4f58276
commit
a42dc35883
|
@ -159,182 +159,114 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 {
|
||||||
protected Set<String> commonMocks(int liveNodesCount) throws Exception {
|
protected Set<String> commonMocks(int liveNodesCount) throws Exception {
|
||||||
|
|
||||||
shardHandlerFactoryMock.getShardHandler();
|
shardHandlerFactoryMock.getShardHandler();
|
||||||
expectLastCall().andAnswer(new IAnswer<ShardHandler>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
log.info("SHARDHANDLER");
|
||||||
public ShardHandler answer() throws Throwable {
|
return shardHandlerMock;
|
||||||
log.info("SHARDHANDLER");
|
|
||||||
return shardHandlerMock;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
workQueueMock.peekTopN(EasyMock.anyInt(), anyObject(Set.class), EasyMock.anyLong());
|
workQueueMock.peekTopN(EasyMock.anyInt(), anyObject(Set.class), EasyMock.anyLong());
|
||||||
expectLastCall().andAnswer(new IAnswer<List>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
Object result;
|
||||||
public List answer() throws Throwable {
|
int count = 0;
|
||||||
Object result;
|
while ((result = queue.peek()) == null) {
|
||||||
int count = 0;
|
Thread.sleep(1000);
|
||||||
while ((result = queue.peek()) == null) {
|
count++;
|
||||||
Thread.sleep(1000);
|
if (count > 1) return null;
|
||||||
count++;
|
|
||||||
if (count > 1) return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Arrays.asList(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Arrays.asList(result);
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
|
|
||||||
workQueueMock.getTailId();
|
workQueueMock.getTailId();
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
Object result = null;
|
||||||
public Object answer() throws Throwable {
|
Iterator iter = queue.iterator();
|
||||||
Object result = null;
|
while(iter.hasNext()) {
|
||||||
Iterator iter = queue.iterator();
|
result = iter.next();
|
||||||
while(iter.hasNext()) {
|
|
||||||
result = iter.next();
|
|
||||||
}
|
|
||||||
return result==null ? null : ((QueueEvent)result).getId();
|
|
||||||
}
|
}
|
||||||
|
return result==null ? null : ((QueueEvent)result).getId();
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
|
|
||||||
workQueueMock.peek(true);
|
workQueueMock.peek(true);
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
Object result;
|
||||||
public Object answer() throws Throwable {
|
while ((result = queue.peek()) == null) {
|
||||||
Object result;
|
Thread.sleep(1000);
|
||||||
while ((result = queue.peek()) == null) {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
|
|
||||||
workQueueMock.remove(anyObject(QueueEvent.class));
|
workQueueMock.remove(anyObject(QueueEvent.class));
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
queue.remove(getCurrentArguments()[0]);
|
||||||
public Object answer() throws Throwable {
|
return null;
|
||||||
queue.remove((QueueEvent) getCurrentArguments()[0]);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
|
|
||||||
workQueueMock.poll();
|
workQueueMock.poll();
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
expectLastCall().andAnswer(() -> queue.poll()).anyTimes();
|
||||||
@Override
|
|
||||||
public Object answer() throws Throwable {
|
|
||||||
return queue.poll();
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
zkStateReaderMock.getClusterState();
|
zkStateReaderMock.getClusterState();
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
expectLastCall().andAnswer(() -> clusterStateMock).anyTimes();
|
||||||
@Override
|
|
||||||
public Object answer() throws Throwable {
|
|
||||||
return clusterStateMock;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
zkStateReaderMock.getZkClient();
|
zkStateReaderMock.getZkClient();
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
expectLastCall().andAnswer(() -> solrZkClientMock).anyTimes();
|
||||||
@Override
|
|
||||||
public Object answer() throws Throwable {
|
|
||||||
return solrZkClientMock;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
zkStateReaderMock.updateClusterState();
|
zkStateReaderMock.updateClusterState();
|
||||||
|
|
||||||
clusterStateMock.getCollections();
|
clusterStateMock.getCollections();
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
expectLastCall().andAnswer(() -> collectionsSet).anyTimes();
|
||||||
@Override
|
|
||||||
public Object answer() throws Throwable {
|
|
||||||
return collectionsSet;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
|
||||||
final Set<String> liveNodes = new HashSet<>();
|
final Set<String> liveNodes = new HashSet<>();
|
||||||
for (int i = 0; i < liveNodesCount; i++) {
|
for (int i = 0; i < liveNodesCount; i++) {
|
||||||
final String address = "localhost:" + (8963 + i) + "_solr";
|
final String address = "localhost:" + (8963 + i) + "_solr";
|
||||||
liveNodes.add(address);
|
liveNodes.add(address);
|
||||||
|
|
||||||
zkStateReaderMock.getBaseUrlForNodeName(address);
|
zkStateReaderMock.getBaseUrlForNodeName(address);
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
// This works as long as this test does not use a
|
||||||
public Object answer() throws Throwable {
|
// webapp context with an underscore in it
|
||||||
// This works as long as this test does not use a
|
return address.replaceAll("_", "/");
|
||||||
// webapp context with an underscore in it
|
|
||||||
return address.replaceAll("_", "/");
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zkStateReaderMock.getClusterProperty("legacyCloud", "true");
|
zkStateReaderMock.getClusterProperty("legacyCloud", "true");
|
||||||
expectLastCall().andAnswer(new IAnswer<String>() {
|
expectLastCall().andAnswer(() -> "true");
|
||||||
@Override
|
|
||||||
public String answer() throws Throwable {
|
|
||||||
return "true";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
solrZkClientMock.getZkClientTimeout();
|
solrZkClientMock.getZkClientTimeout();
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
expectLastCall().andAnswer(() -> 30000).anyTimes();
|
||||||
@Override
|
|
||||||
public Object answer() throws Throwable {
|
|
||||||
return 30000;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
clusterStateMock.hasCollection(anyObject(String.class));
|
clusterStateMock.hasCollection(anyObject(String.class));
|
||||||
expectLastCall().andAnswer(new IAnswer<Boolean>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
String key = (String) getCurrentArguments()[0];
|
||||||
public Boolean answer() throws Throwable {
|
return collectionsSet.contains(key);
|
||||||
String key = (String) getCurrentArguments()[0];
|
}).anyTimes();
|
||||||
return collectionsSet.contains(key);
|
|
||||||
}
|
|
||||||
} ).anyTimes();
|
|
||||||
|
|
||||||
|
|
||||||
clusterStateMock.getLiveNodes();
|
clusterStateMock.getLiveNodes();
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
expectLastCall().andAnswer(() -> liveNodes).anyTimes();
|
||||||
@Override
|
|
||||||
public Object answer() throws Throwable {
|
|
||||||
return liveNodes;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
|
||||||
solrZkClientMock.create(anyObject(String.class), anyObject(byte[].class), anyObject(CreateMode.class), anyBoolean());
|
solrZkClientMock.create(anyObject(String.class), anyObject(byte[].class), anyObject(CreateMode.class), anyBoolean());
|
||||||
expectLastCall().andAnswer(new IAnswer<String>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
String key = (String) getCurrentArguments()[0];
|
||||||
public String answer() throws Throwable {
|
zkMap.put(key, null);
|
||||||
String key = (String) getCurrentArguments()[0];
|
handleCreateCollMessage((byte[]) getCurrentArguments()[1]);
|
||||||
zkMap.put(key, null);
|
return key;
|
||||||
handleCreateCollMessage((byte[]) getCurrentArguments()[1]);
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
|
|
||||||
solrZkClientMock.makePath(anyObject(String.class), anyObject(byte[].class), anyBoolean());
|
solrZkClientMock.makePath(anyObject(String.class), anyObject(byte[].class), anyBoolean());
|
||||||
expectLastCall().andAnswer(new IAnswer<String>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
String key = (String) getCurrentArguments()[0];
|
||||||
public String answer() throws Throwable {
|
return key;
|
||||||
String key = (String) getCurrentArguments()[0];
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
|
|
||||||
solrZkClientMock.makePath(anyObject(String.class), anyObject(byte[].class), anyObject(CreateMode.class), anyBoolean());
|
solrZkClientMock.makePath(anyObject(String.class), anyObject(byte[].class), anyObject(CreateMode.class), anyBoolean());
|
||||||
expectLastCall().andAnswer(new IAnswer<String>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
String key = (String) getCurrentArguments()[0];
|
||||||
public String answer() throws Throwable {
|
return key;
|
||||||
String key = (String) getCurrentArguments()[0];
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
|
|
||||||
solrZkClientMock.exists(anyObject(String.class),anyBoolean());
|
solrZkClientMock.exists(anyObject(String.class),anyBoolean());
|
||||||
expectLastCall().andAnswer(new IAnswer<Boolean>() {
|
expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
String key = (String) getCurrentArguments()[0];
|
||||||
public Boolean answer() throws Throwable {
|
return zkMap.containsKey(key);
|
||||||
String key = (String) getCurrentArguments()[0];
|
|
||||||
return zkMap.containsKey(key);
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
|
|
||||||
zkMap.put("/configs/myconfig", null);
|
zkMap.put("/configs/myconfig", null);
|
||||||
|
|
|
@ -100,13 +100,7 @@ public class TestPKIAuthenticationPlugin extends SolrTestCaseJ4 {
|
||||||
assertTrue(header.get().getValue().startsWith(nodeName));
|
assertTrue(header.get().getValue().startsWith(nodeName));
|
||||||
final AtomicReference<ServletRequest> wrappedRequestByFilter = new AtomicReference<>();
|
final AtomicReference<ServletRequest> wrappedRequestByFilter = new AtomicReference<>();
|
||||||
HttpServletRequest mockReq = createMockRequest(header);
|
HttpServletRequest mockReq = createMockRequest(header);
|
||||||
FilterChain filterChain = new FilterChain() {
|
FilterChain filterChain = (servletRequest, servletResponse) -> wrappedRequestByFilter.set(servletRequest);
|
||||||
@Override
|
|
||||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
|
|
||||||
throws IOException, ServletException {
|
|
||||||
wrappedRequestByFilter.set(servletRequest);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mock.doAuthenticate(mockReq, null, filterChain);
|
mock.doAuthenticate(mockReq, null, filterChain);
|
||||||
|
|
||||||
assertNotNull(wrappedRequestByFilter.get());
|
assertNotNull(wrappedRequestByFilter.get());
|
||||||
|
@ -164,30 +158,17 @@ public class TestPKIAuthenticationPlugin extends SolrTestCaseJ4 {
|
||||||
HttpServletRequest mockReq = EasyMock.createMock(HttpServletRequest.class);
|
HttpServletRequest mockReq = EasyMock.createMock(HttpServletRequest.class);
|
||||||
EasyMock.reset(mockReq);
|
EasyMock.reset(mockReq);
|
||||||
mockReq.getHeader(EasyMock.anyObject(String.class));
|
mockReq.getHeader(EasyMock.anyObject(String.class));
|
||||||
EasyMock.expectLastCall().andAnswer(new IAnswer<String>() {
|
EasyMock.expectLastCall().andAnswer(() -> {
|
||||||
@Override
|
if (PKIAuthenticationPlugin.HEADER.equals(getCurrentArguments()[0])) {
|
||||||
public String answer() throws Throwable {
|
if (header.get() == null) return null;
|
||||||
if (PKIAuthenticationPlugin.HEADER.equals(getCurrentArguments()[0])) {
|
return header.get().getValue();
|
||||||
if (header.get() == null) return null;
|
} else return null;
|
||||||
return header.get().getValue();
|
|
||||||
} else return null;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
}).anyTimes();
|
||||||
mockReq.getUserPrincipal();
|
mockReq.getUserPrincipal();
|
||||||
EasyMock.expectLastCall().andAnswer(new IAnswer<Principal>() {
|
EasyMock.expectLastCall().andAnswer(() -> null).anyTimes();
|
||||||
@Override
|
|
||||||
public Principal answer() throws Throwable {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
mockReq.getRequestURI();
|
mockReq.getRequestURI();
|
||||||
EasyMock.expectLastCall().andAnswer(new IAnswer<String>() {
|
EasyMock.expectLastCall().andAnswer(() -> "/collection1/select").anyTimes();
|
||||||
@Override
|
|
||||||
public String answer() throws Throwable {
|
|
||||||
return "/collection1/select";
|
|
||||||
}
|
|
||||||
}).anyTimes();
|
|
||||||
|
|
||||||
EasyMock.replay(mockReq);
|
EasyMock.replay(mockReq);
|
||||||
return mockReq;
|
return mockReq;
|
||||||
|
|
Loading…
Reference in New Issue