use of org.apache.shenyu.sync.data.api.AuthDataSubscriber in project incubator-shenyu by apache.
the class ZookeeperSyncDataServiceTest method testWatchAppAuthWhenInit.
@Test
public void testWatchAppAuthWhenInit() {
final List<AppAuthData> subscribeList = new ArrayList<>(1);
AuthDataSubscriber authDataSubscriber = new AuthDataSubscriber() {
@Override
public void onSubscribe(final AppAuthData appAuthData) {
subscribeList.add(appAuthData);
}
@Override
public void unSubscribe(final AppAuthData appAuthData) {
}
};
syncDataService = new ZookeeperSyncDataService(zkClient, null, Collections.emptyList(), Lists.newArrayList(authDataSubscriber));
assertThat(subscribeList.size(), is(1));
}
use of org.apache.shenyu.sync.data.api.AuthDataSubscriber in project incubator-shenyu by apache.
the class ZookeeperSyncDataServiceTest method testWatchAppAuthWhenDataDeleted.
@Test
public void testWatchAppAuthWhenDataDeleted() throws Exception {
final List<AppAuthData> unSubscribeList = new ArrayList<>(1);
AuthDataSubscriber authDataSubscriber = new AuthDataSubscriber() {
@Override
public void onSubscribe(final AppAuthData appAuthData) {
}
@Override
public void unSubscribe(final AppAuthData appAuthData) {
unSubscribeList.add(appAuthData);
}
};
syncDataService = new ZookeeperSyncDataService(zkClient, null, Collections.emptyList(), Lists.newArrayList(authDataSubscriber));
ArgumentCaptor<IZkDataListener> captor = ArgumentCaptor.forClass(IZkDataListener.class);
verify(zkClient).subscribeDataChanges(eq(MOCK_APP_AUTH_PATH), captor.capture());
captor.getValue().handleDataDeleted(MOCK_APP_AUTH_PATH);
assertThat(unSubscribeList.size(), is(1));
assertThat(unSubscribeList.get(0).getAppKey(), is(MOCK_APP_AUTH_KEY));
}
use of org.apache.shenyu.sync.data.api.AuthDataSubscriber in project incubator-shenyu by apache.
the class NacosCacheHandlerTest method testUpdateAuthMap.
@Test
public void testUpdateAuthMap() throws NacosException {
String mockAppKey = "MOCK_APP_KEY";
String mockAppKey2 = "MOCK_APP_KEY2";
String mockAppSecret = "MOCK_APP_SECRET";
AppAuthData appAuthData = AppAuthData.builder().appKey(mockAppKey).appSecret(mockAppSecret).enabled(true).build();
AppAuthData appAuthData2 = AppAuthData.builder().appKey(mockAppKey2).appSecret(mockAppSecret).enabled(true).build();
changeAuthData(ImmutableList.of(appAuthData, appAuthData2));
String appAuthDataParam = GsonUtils.getInstance().toJson(ImmutableMap.of(mockAppKey2, appAuthData2, mockAppKey, appAuthData));
final CountDownLatch latch = new CountDownLatch(2);
final List<AppAuthData> subscribeList = new ArrayList<>();
final List<AppAuthData> unsubscribeList = new ArrayList<>();
AuthDataSubscriber authDataSubscriber = new AuthDataSubscriber() {
@Override
public void onSubscribe(final AppAuthData appAuthData) {
subscribeList.add(appAuthData);
latch.countDown();
}
@Override
public void unSubscribe(final AppAuthData appAuthData) {
unsubscribeList.add(appAuthData);
latch.countDown();
}
};
nacosCacheHandlerService = new NacosCacheHandler(configService, null, Collections.emptyList(), Lists.newArrayList(authDataSubscriber));
nacosCacheHandlerService.updateAuthMap(appAuthDataParam);
assertEquals(2, subscribeList.size());
assertEquals(2, unsubscribeList.size());
assertEquals(configService.getConfig(AUTH_DATA_ID, GROUP, 100), GsonUtils.getInstance().toJson(ImmutableMap.of(mockAppKey2, appAuthData2, mockAppKey, appAuthData)));
}
use of org.apache.shenyu.sync.data.api.AuthDataSubscriber in project incubator-shenyu by apache.
the class NacosCacheHandlerTest method testWatcherData.
@Test
public void testWatcherData() throws NacosException {
String mockAppKey = "MOCK_APP_KEY";
String mockAppKey2 = "MOCK_APP_KEY2";
String mockAppSecret = "MOCK_APP_SECRET";
AppAuthData appAuthData = AppAuthData.builder().appKey(mockAppKey).appSecret(mockAppSecret).enabled(true).build();
AppAuthData appAuthData2 = AppAuthData.builder().appKey(mockAppKey2).appSecret(mockAppSecret).enabled(true).build();
changeAuthData(ImmutableList.of(appAuthData, appAuthData2));
final CountDownLatch latch = new CountDownLatch(2);
AuthDataSubscriber authDataSubscriber = new AuthDataSubscriber() {
@Override
public void onSubscribe(final AppAuthData appAuthData) {
latch.countDown();
}
@Override
public void unSubscribe(final AppAuthData appAuthData) {
latch.countDown();
}
};
nacosCacheHandlerService = new NacosCacheHandler(configService, null, Collections.emptyList(), Lists.newArrayList(authDataSubscriber));
NacosCacheHandler.OnChange oc = nacosCacheHandlerService::updateAuthMap;
nacosCacheHandlerService.watcherData(AUTH_DATA_ID, oc);
}
use of org.apache.shenyu.sync.data.api.AuthDataSubscriber in project incubator-shenyu by apache.
the class AppAuthDataRefreshTest method buildMockAppAuthDataRefresh.
private AppAuthDataRefresh buildMockAppAuthDataRefresh() {
List<AuthDataSubscriber> authDataSubscribers = new ArrayList<>();
authDataSubscribers.add(new AuthDataSubscriber() {
@Override
public void onSubscribe(final AppAuthData appAuthData) {
}
@Override
public void unSubscribe(final AppAuthData appAuthData) {
}
});
return new AppAuthDataRefresh(authDataSubscribers);
}
Aggregations