diff --git a/extension-impl/registry-local/src/main/java/com/alipay/sofa/rpc/registry/local/LocalRegistry.java b/extension-impl/registry-local/src/main/java/com/alipay/sofa/rpc/registry/local/LocalRegistry.java index f73fb75cd..49dd3c785 100644 --- a/extension-impl/registry-local/src/main/java/com/alipay/sofa/rpc/registry/local/LocalRegistry.java +++ b/extension-impl/registry-local/src/main/java/com/alipay/sofa/rpc/registry/local/LocalRegistry.java @@ -356,7 +356,7 @@ public void destroy() { * * @param newCache the new cache */ - private void notifyConsumer(Map newCache) { + void notifyConsumer(Map newCache) { Map oldCache = memoryCache; // 比较两个map的差异 MapDifference difference = @@ -379,7 +379,7 @@ private void notifyConsumer(Map newCache) { LOGGER.debug("{} has differente", entry.getKey()); } ValueDifference differentValue = entry.getValue(); - ProviderGroup innew = differentValue.rightValue(); + ProviderGroup innew = differentValue.leftValue(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("new(right) is {}", innew); } diff --git a/extension-impl/registry-local/src/test/java/com/alipay/sofa/rpc/registry/local/LocalRegistryTest.java b/extension-impl/registry-local/src/test/java/com/alipay/sofa/rpc/registry/local/LocalRegistryTest.java index 0725c6b0c..a98ad65f0 100644 --- a/extension-impl/registry-local/src/test/java/com/alipay/sofa/rpc/registry/local/LocalRegistryTest.java +++ b/extension-impl/registry-local/src/test/java/com/alipay/sofa/rpc/registry/local/LocalRegistryTest.java @@ -17,6 +17,7 @@ package com.alipay.sofa.rpc.registry.local; import com.alipay.sofa.rpc.client.ProviderGroup; +import com.alipay.sofa.rpc.client.ProviderInfo; import com.alipay.sofa.rpc.common.RpcConstants; import com.alipay.sofa.rpc.common.utils.FileUtils; import com.alipay.sofa.rpc.config.ApplicationConfig; @@ -108,6 +109,9 @@ public static void main(String[] args) { @Test public void testAll() throws Exception { + // test for notifyConsumer + notifyConsumerTest(); + int timeoutPerSub = 5000; ServerConfig serverConfig = new ServerConfig() @@ -229,6 +233,31 @@ public void testAll() throws Exception { Assert.assertTrue(registry.notifyListeners.size() == 0); } + public void notifyConsumerTest() { + LocalRegistry registry = new LocalRegistry(new RegistryConfig()); + ConsumerConfig consumer = new ConsumerConfig(); + consumer.setInterfaceId("test"); + LocalRegistryTest.MockProviderInfoListener providerInfoListener = new LocalRegistryTest.MockProviderInfoListener(); + consumer.setProviderInfoListener(providerInfoListener); + registry.subscribe(consumer); + String key = LocalRegistryHelper.buildListDataId(consumer, consumer.getProtocol()); + + registry.memoryCache.put(key, new ProviderGroup()); + + Map newCache = new HashMap(); + ProviderGroup newProviderGroup = new ProviderGroup(); + ProviderInfo providerInfo = new ProviderInfo().setHost("0.0.0.0"); + newProviderGroup.add(providerInfo); + newCache.put(key, newProviderGroup); + + registry.notifyConsumer(newCache); + + Map ps = providerInfoListener.getData(); + Assert.assertTrue(ps.size() > 0); + Assert.assertNotNull(ps.get(RpcConstants.ADDRESS_DEFAULT_GROUP)); + Assert.assertTrue(ps.get(RpcConstants.ADDRESS_DEFAULT_GROUP).size() == 1); + } + private static class MockProviderInfoListener implements ProviderInfoListener { Map ps = new HashMap();