Skip to content

Commit

Permalink
Incorrectly provider list notified when scanning file changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyunbin authored and ujjboy committed Jul 7, 2018
1 parent 3f94a24 commit 4b4b1da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public void destroy() {
*
* @param newCache the new cache
*/
private void notifyConsumer(Map<String, ProviderGroup> newCache) {
void notifyConsumer(Map<String, ProviderGroup> newCache) {
Map<String, ProviderGroup> oldCache = memoryCache;
// 比较两个map的差异
MapDifference<String, ProviderGroup> difference =
Expand All @@ -379,7 +379,7 @@ private void notifyConsumer(Map<String, ProviderGroup> newCache) {
LOGGER.debug("{} has differente", entry.getKey());
}
ValueDifference<ProviderGroup> differentValue = entry.getValue();
ProviderGroup innew = differentValue.rightValue();
ProviderGroup innew = differentValue.leftValue();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("new(right) is {}", innew);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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<String, ProviderGroup> newCache = new HashMap<String, ProviderGroup>();
ProviderGroup newProviderGroup = new ProviderGroup();
ProviderInfo providerInfo = new ProviderInfo().setHost("0.0.0.0");
newProviderGroup.add(providerInfo);
newCache.put(key, newProviderGroup);

registry.notifyConsumer(newCache);

Map<String, ProviderGroup> 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<String, ProviderGroup> ps = new HashMap<String, ProviderGroup>();
Expand Down

0 comments on commit 4b4b1da

Please sign in to comment.