From 8276a62b421f8980328b98eea98ccc1d1197a2fd Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Wed, 25 May 2016 23:11:59 +0530 Subject: [PATCH] SOLR-8995: Replace anonymous implementations of SAM interfaces with Lambdas --- ...rseerCollectionConfigSetProcessorTest.java | 178 ++++++------------ .../security/TestPKIAuthenticationPlugin.java | 35 +--- 2 files changed, 63 insertions(+), 150 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionConfigSetProcessorTest.java b/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionConfigSetProcessorTest.java index 8efb60525a0..4658367ad52 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionConfigSetProcessorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionConfigSetProcessorTest.java @@ -159,182 +159,114 @@ public class OverseerCollectionConfigSetProcessorTest extends SolrTestCaseJ4 { protected Set commonMocks(int liveNodesCount) throws Exception { shardHandlerFactoryMock.getShardHandler(); - expectLastCall().andAnswer(new IAnswer() { - @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() { - @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() { - @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() { - @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() { - @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() { - @Override - public Object answer() throws Throwable { - return queue.poll(); - } - }).anyTimes(); + expectLastCall().andAnswer(() -> queue.poll()).anyTimes(); zkStateReaderMock.getClusterState(); - expectLastCall().andAnswer(new IAnswer() { - @Override - public Object answer() throws Throwable { - return clusterStateMock; - } - }).anyTimes(); + expectLastCall().andAnswer(() -> clusterStateMock).anyTimes(); zkStateReaderMock.getZkClient(); - expectLastCall().andAnswer(new IAnswer() { - @Override - public Object answer() throws Throwable { - return solrZkClientMock; - } - }).anyTimes(); + expectLastCall().andAnswer(() -> solrZkClientMock).anyTimes(); zkStateReaderMock.updateClusterState(); clusterStateMock.getCollections(); - expectLastCall().andAnswer(new IAnswer() { - @Override - public Object answer() throws Throwable { - return collectionsSet; - } - }).anyTimes(); + expectLastCall().andAnswer(() -> collectionsSet).anyTimes(); final Set 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() { - @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() { - @Override - public String answer() throws Throwable { - return "true"; - } - }); + expectLastCall().andAnswer(() -> "true"); solrZkClientMock.getZkClientTimeout(); - expectLastCall().andAnswer(new IAnswer() { - @Override - public Object answer() throws Throwable { - return 30000; - } - }).anyTimes(); + expectLastCall().andAnswer(() -> 30000).anyTimes(); clusterStateMock.hasCollection(anyObject(String.class)); - expectLastCall().andAnswer(new IAnswer() { - @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() { - @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() { - @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() { - @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() { - @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() { - @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); diff --git a/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java b/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java index ba7d46d7d43..2f102bfa4e6 100644 --- a/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java +++ b/solr/core/src/test/org/apache/solr/security/TestPKIAuthenticationPlugin.java @@ -100,13 +100,7 @@ public class TestPKIAuthenticationPlugin extends SolrTestCaseJ4 { assertTrue(header.get().getValue().startsWith(nodeName)); final AtomicReference 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() { - @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() { - @Override - public Principal answer() throws Throwable { - return null; - } - }).anyTimes(); + EasyMock.expectLastCall().andAnswer(() -> null).anyTimes(); mockReq.getRequestURI(); - EasyMock.expectLastCall().andAnswer(new IAnswer() { - @Override - public String answer() throws Throwable { - return "/collection1/select"; - } - }).anyTimes(); + EasyMock.expectLastCall().andAnswer(() -> "/collection1/select").anyTimes(); EasyMock.replay(mockReq); return mockReq;