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