Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect provider list notified when scanning file changes. #219

Merged
merged 4 commits into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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