use of org.apache.shenyu.sync.data.api.MetaDataSubscriber in project incubator-shenyu by apache.
the class ZookeeperSyncDataServiceTest method testWatchMetaDataWhenDataChange.
@Test
public void testWatchMetaDataWhenDataChange() throws Exception {
final MetaData changedMetaData = MetaData.builder().id(MOCK_META_DATA_ID).enabled(Boolean.TRUE).build();
final List<MetaData> subscribeList = new ArrayList<>(2);
MetaDataSubscriber metaDataSubscriber = new MetaDataSubscriber() {
@Override
public void onSubscribe(final MetaData metaData) {
subscribeList.add(metaData);
}
@Override
public void unSubscribe(final MetaData metaData) {
}
};
syncDataService = new ZookeeperSyncDataService(zkClient, null, Lists.newArrayList(metaDataSubscriber), Collections.emptyList());
assertEquals(1, subscribeList.size());
ArgumentCaptor<IZkDataListener> captor = ArgumentCaptor.forClass(IZkDataListener.class);
verify(zkClient).subscribeDataChanges(eq(MOCK_META_DATA_PATH), captor.capture());
captor.getValue().handleDataChange(MOCK_META_DATA_PATH, GsonUtils.getInstance().toJson(changedMetaData));
assertThat(subscribeList.size(), is(2));
assertTrue(subscribeList.get(1).getEnabled());
}
use of org.apache.shenyu.sync.data.api.MetaDataSubscriber in project incubator-shenyu by apache.
the class ZookeeperSyncDataServiceTest method testWatchMetaDataWhenInit.
@Test
public void testWatchMetaDataWhenInit() {
final List<MetaData> subscribeList = new ArrayList<>(1);
MetaDataSubscriber metaDataSubscriber = new MetaDataSubscriber() {
@Override
public void onSubscribe(final MetaData metaData) {
subscribeList.add(metaData);
}
@Override
public void unSubscribe(final MetaData metaData) {
}
};
syncDataService = new ZookeeperSyncDataService(zkClient, null, Lists.newArrayList(metaDataSubscriber), Collections.emptyList());
assertThat(subscribeList.size(), is(1));
}
use of org.apache.shenyu.sync.data.api.MetaDataSubscriber in project incubator-shenyu by apache.
the class NacosCacheHandlerTest method testUpdateMetaDataMap.
@Test
public void testUpdateMetaDataMap() throws NacosException {
String metadataPath1 = "METADATA_PATH_1";
String metadataPath2 = "METADATA_PATH_2";
MetaData metaData1 = MetaData.builder().path(metadataPath1).id("meta_1").build();
MetaData metaData2 = MetaData.builder().path(metadataPath2).id("meta_2").build();
changeMetaData(ImmutableList.of(metaData1, metaData2));
String metaDataParam = GsonUtils.getInstance().toJson(ImmutableMap.of(metadataPath1, metaData1, metadataPath2, metaData2));
final CountDownLatch latch = new CountDownLatch(2);
final List<MetaData> subscribeList = new ArrayList<>();
final List<MetaData> unsubscribeList = new ArrayList<>();
MetaDataSubscriber metaDataSubscriber = new MetaDataSubscriber() {
@Override
public void onSubscribe(final MetaData metaData) {
subscribeList.add(metaData);
latch.countDown();
}
@Override
public void unSubscribe(final MetaData metaData) {
unsubscribeList.add(metaData);
latch.countDown();
}
};
nacosCacheHandlerService = new NacosCacheHandler(configService, null, Lists.newArrayList(metaDataSubscriber), Collections.emptyList());
nacosCacheHandlerService.updateMetaDataMap(metaDataParam);
assertEquals(2, subscribeList.size());
assertEquals(2, unsubscribeList.size());
assertEquals(configService.getConfig(META_DATA_ID, GROUP, 1), GsonUtils.getInstance().toJson(ImmutableMap.of(metadataPath1, metaData1, metadataPath2, metaData2)));
}
use of org.apache.shenyu.sync.data.api.MetaDataSubscriber in project incubator-shenyu by apache.
the class ConsulCacheHandlerTest method testUpdateMetaDataMap.
@Test
public void testUpdateMetaDataMap() {
String metadataPath1 = "METADATA_PATH_1";
String metadataPath2 = "METADATA_PATH_2";
MetaData metaData1 = MetaData.builder().path(metadataPath1).id("meta_1").build();
MetaData metaData2 = MetaData.builder().path(metadataPath2).id("meta_2").build();
String metaDataParam = GsonUtils.getInstance().toJson(ImmutableMap.of(metadataPath1, metaData1, metadataPath2, metaData2));
final List<MetaData> subscribeList = new ArrayList<>();
final List<MetaData> unsubscribeList = new ArrayList<>();
MetaDataSubscriber metaDataSubscriber = new MetaDataSubscriber() {
@Override
public void onSubscribe(final MetaData metaData) {
subscribeList.add(metaData);
}
@Override
public void unSubscribe(final MetaData metaData) {
unsubscribeList.add(metaData);
}
};
ConsulCacheHandler consulCacheHandler = new ConsulCacheHandler(null, Lists.newArrayList(metaDataSubscriber), Collections.emptyList());
consulCacheHandler.updateMetaDataMap(metaDataParam);
assertEquals(2, subscribeList.size());
assertEquals(2, unsubscribeList.size());
}
use of org.apache.shenyu.sync.data.api.MetaDataSubscriber in project incubator-shenyu by apache.
the class GlobalPluginConfigurationTest method testMetaDataCacheSubscriber.
@Test
public void testMetaDataCacheSubscriber() {
applicationContextRunner.run(context -> {
MetaDataSubscriber subscriber = context.getBean("metaDataCacheSubscriber", MetaDataSubscriber.class);
assertNotNull(subscriber);
});
}
Aggregations