diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalanceTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalanceTest.java index 7281fdbdebb..bd660e642ff 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalanceTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalanceTest.java @@ -31,8 +31,8 @@ public class ConsistentHashLoadBalanceTest extends LoadBalanceBaseTest { public void testConsistentHashLoadBalance() { int runs = 10000; Map counter = getInvokeCounter(runs, ConsistentHashLoadBalance.NAME); - for (Invoker minvoker : counter.keySet()) { - Long count = counter.get(minvoker).get(); + for (Map.Entry entry : counter.entrySet()) { + Long count = entry.getValue().get(); Assert.assertTrue("abs diff should < avg", Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size())); } } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveBalanceTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveBalanceTest.java index 836994fdcc8..c54e9a00304 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveBalanceTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveBalanceTest.java @@ -30,8 +30,8 @@ public class LeastActiveBalanceTest extends LoadBalanceBaseTest { public void testLeastActiveLoadBalance_select() { int runs = 10000; Map counter = getInvokeCounter(runs, LeastActiveLoadBalance.NAME); - for (Invoker minvoker : counter.keySet()) { - Long count = counter.get(minvoker).get(); + for (Map.Entry entry : counter.entrySet()) { + Long count = entry.getValue().get(); // System.out.println(count); Assert.assertTrue("abs diff shoud < avg", Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size())); diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalanceTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalanceTest.java index d31a85d08d4..3b65ee39580 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalanceTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalanceTest.java @@ -32,8 +32,8 @@ public class RandomLoadBalanceTest extends LoadBalanceBaseTest { public void testRandomLoadBalanceSelect() { int runs = 1000; Map counter = getInvokeCounter(runs, RandomLoadBalance.NAME); - for (Invoker minvoker : counter.keySet()) { - Long count = counter.get(minvoker).get(); + for (Map.Entry entry : counter.entrySet()) { + Long count = entry.getValue().get(); Assert.assertTrue("abs diff should < avg", Math.abs(count - runs / (0f + invokers.size())) < runs / (0f + invokers.size())); } @@ -43,8 +43,8 @@ public void testRandomLoadBalanceSelect() { } } counter = getInvokeCounter(runs, LeastActiveLoadBalance.NAME); - for (Invoker minvoker : counter.keySet()) { - Long count = counter.get(minvoker).get(); + for (Map.Entry entry : counter.entrySet()) { + Long count = entry.getValue().get(); } Assert.assertEquals(runs, counter.get(invoker1).intValue()); Assert.assertEquals(0, counter.get(invoker2).intValue()); diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalanceTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalanceTest.java index 5242f90bada..93c89eff978 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalanceTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalanceTest.java @@ -47,8 +47,8 @@ private void assertStrictWRRResult(int loop, Map resultMa public void testRoundRobinLoadBalanceSelect() { int runs = 10000; Map counter = getInvokeCounter(runs, RoundRobinLoadBalance.NAME); - for (Invoker minvoker : counter.keySet()) { - Long count = counter.get(minvoker).get(); + for (Map.Entry entry : counter.entrySet()) { + Long count = entry.getValue().get(); Assert.assertTrue("abs diff should < 1", Math.abs(count - runs / (0f + invokers.size())) < 1f); } } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java index 2039b0a0e4c..0344ee1b1a1 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java @@ -432,10 +432,10 @@ public void testSelectBalance() { counter.get(sinvoker).incrementAndGet(); } - for (Invoker minvoker : counter.keySet()) { - Long count = counter.get(minvoker).get(); + for (Map.Entry entry : counter.entrySet()) { + Long count = entry.getValue().get(); // System.out.println(count); - if (minvoker.isAvailable()) + if (entry.getKey().isAvailable()) Assert.assertTrue("count should > avg", count > runs / invokers.size()); } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/Menu.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/Menu.java index b3564d27ae7..5f2b56143f8 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/Menu.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/Menu.java @@ -30,8 +30,8 @@ public Menu() { } public Menu(Map> menus) { - for (String key : menus.keySet()) { - this.menus.put(key, new ArrayList(menus.get(key))); + for (Map.Entry> entry : menus.entrySet()) { + this.menus.put(entry.getKey(), new ArrayList(entry.getValue())); } } diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java index 12d6ba41e3c..ba0b617b88c 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java @@ -161,11 +161,11 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl merge(expected, firstMenuMap); merge(expected, secondMenuMap); assertEquals(expected.keySet(), menu.getMenus().keySet()); - for (String key : expected.keySet()) { + for (Map.Entry> entry : expected.entrySet()) { // FIXME: cannot guarantee the sequence of the merge result, check implementation in // MergeableClusterInvoker#invoke - List values1 = new ArrayList(expected.get(key)); - List values2 = new ArrayList(menu.getMenus().get(key)); + List values1 = new ArrayList(entry.getValue()); + List values2 = new ArrayList(menu.getMenus().get(entry.getKey())); Collections.sort(values1); Collections.sort(values2); assertEquals(values1, values2); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java b/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java index a1bdc7af5eb..995965ac74a 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java @@ -144,12 +144,11 @@ private static void serializeInternal(JavaBeanDescriptor descriptor, Object obj, } } else if (obj instanceof Map) { Map map = (Map) obj; - for (Object key : map.keySet()) { - Object value = map.get(key); + map.forEach((key, value) -> { Object keyDescriptor = key == null ? null : createDescriptorIfAbsent(key, accessor, cache); Object valueDescriptor = value == null ? null : createDescriptorIfAbsent(value, accessor, cache); descriptor.setProperty(keyDescriptor, valueDescriptor); - } // ~ end of loop map + });// ~ end of loop map } else { if (JavaBeanAccessor.isAccessByMethod(accessor)) { Map methods = ReflectUtils.getBeanPropertyReadMethods(obj.getClass()); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java index 5fa6cfe9a47..5ec3fbec44f 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java @@ -126,9 +126,9 @@ public static void sent(Channel channel, Request request) { * @param channel channel to close */ public static void closeChannel(Channel channel) { - for (long id : CHANNELS.keySet()) { - if (channel.equals(CHANNELS.get(id))) { - DefaultFuture future = getFuture(id); + for (Map.Entry entry: CHANNELS.entrySet()) { + if (channel.equals(entry.getValue())) { + DefaultFuture future = getFuture(entry.getKey()); if (future != null && !future.isDone()) { Response disconnectResponse = new Response(future.getId()); disconnectResponse.setStatus(Response.CHANNEL_INACTIVE); diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/ExchangeCodecTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/ExchangeCodecTest.java index 5c0d9012c2c..2d026edecbd 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/ExchangeCodecTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/ExchangeCodecTest.java @@ -41,6 +41,7 @@ import java.io.IOException; import java.util.Date; import java.util.HashMap; +import java.util.Map; import static org.junit.Assert.fail; @@ -114,8 +115,8 @@ public void test_Decode_Error_MagicNum() throws IOException { inputBytes.put(new byte[]{MAGIC_HIGH, 0}, TelnetCodec.DecodeResult.NEED_MORE_INPUT); inputBytes.put(new byte[]{0, MAGIC_LOW}, TelnetCodec.DecodeResult.NEED_MORE_INPUT); - for (byte[] input : inputBytes.keySet()) { - testDecode_assertEquals(assemblyDataProtocol(input), inputBytes.get(input)); + for (Map.Entry entry: inputBytes.entrySet()) { + testDecode_assertEquals(assemblyDataProtocol(entry.getKey()), entry.getValue()); } } diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/TelnetCodecTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/TelnetCodecTest.java index 4a81121317a..47eb2212687 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/TelnetCodecTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/TelnetCodecTest.java @@ -35,6 +35,7 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.HashMap; +import java.util.Map; public class TelnetCodecTest { protected Codec2 codec; @@ -235,8 +236,8 @@ public void testDecode_WithExitByte() throws IOException { exitbytes.put(new byte[]{1, -1, -12, -1, -3, 6}, false); //must equal the bytes exitbytes.put(new byte[]{-1, -19, -1, -3, 6}, true); /* Linux Pause */ - for (byte[] exit : exitbytes.keySet()) { - testDecode_WithExitByte(exit, exitbytes.get(exit)); + for (Map.Entry entry : exitbytes.entrySet()) { + testDecode_WithExitByte(entry.getKey(), entry.getValue()); } }