Search in sources :

Example 1 with PluginData

use of org.apache.shenyu.common.dto.PluginData in project incubator-shenyu by apache.

the class ZookeeperDataChangedListener method onPluginChanged.

@Override
public void onPluginChanged(final List<PluginData> changed, final DataEventTypeEnum eventType) {
    for (PluginData data : changed) {
        String pluginPath = DefaultPathConstants.buildPluginPath(data.getName());
        // delete
        if (eventType == DataEventTypeEnum.DELETE) {
            deleteZkPathRecursive(pluginPath);
            String selectorParentPath = DefaultPathConstants.buildSelectorParentPath(data.getName());
            deleteZkPathRecursive(selectorParentPath);
            String ruleParentPath = DefaultPathConstants.buildRuleParentPath(data.getName());
            deleteZkPathRecursive(ruleParentPath);
            continue;
        }
        // create or update
        insertZkNode(pluginPath, data);
    }
}
Also used : PluginData(org.apache.shenyu.common.dto.PluginData)

Example 2 with PluginData

use of org.apache.shenyu.common.dto.PluginData in project incubator-shenyu by apache.

the class SyncDataServiceTest method syncAllTest.

@Test
public void syncAllTest() {
    PluginData pluginData = buildPluginData();
    SelectorData selectorData = buildSelectorData();
    RuleData ruleData = buildRuleData();
    given(this.appAuthService.syncData()).willReturn(ShenyuAdminResult.success());
    given(this.pluginService.listAll()).willReturn(Collections.singletonList(pluginData));
    given(this.selectorService.listAll()).willReturn(Collections.singletonList(selectorData));
    given(this.ruleService.listAll()).willReturn(Collections.singletonList(ruleData));
    assertThat(syncDataService.syncAll(DataEventTypeEnum.CREATE), greaterThan(false));
}
Also used : RuleData(org.apache.shenyu.common.dto.RuleData) PluginData(org.apache.shenyu.common.dto.PluginData) SelectorData(org.apache.shenyu.common.dto.SelectorData) Test(org.junit.jupiter.api.Test)

Example 3 with PluginData

use of org.apache.shenyu.common.dto.PluginData in project incubator-shenyu by apache.

the class BaseDataCacheTest method testCleanPluginData.

@Test
public void testCleanPluginData() throws NoSuchFieldException, IllegalAccessException {
    PluginData firstCachedPluginData = PluginData.builder().name(mockName1).build();
    PluginData secondCachedPluginData = PluginData.builder().name(mockName2).build();
    ConcurrentHashMap<String, PluginData> pluginMap = getFieldByName(pluginMapStr);
    pluginMap.put(mockName1, firstCachedPluginData);
    pluginMap.put(mockName2, secondCachedPluginData);
    assertNotNull(pluginMap.get(mockName1));
    assertNotNull(pluginMap.get(mockName2));
    BaseDataCache.getInstance().cleanPluginData();
    assertNull(pluginMap.get(mockName1));
    assertNull(pluginMap.get(mockName2));
}
Also used : PluginData(org.apache.shenyu.common.dto.PluginData) Test(org.junit.jupiter.api.Test)

Example 4 with PluginData

use of org.apache.shenyu.common.dto.PluginData in project incubator-shenyu by apache.

the class BaseDataCacheTest method testCachePluginData.

@Test
public void testCachePluginData() throws NoSuchFieldException, IllegalAccessException {
    PluginData pluginData = PluginData.builder().name(mockName1).build();
    ConcurrentHashMap<String, PluginData> pluginMap = getFieldByName(pluginMapStr);
    assertNull(pluginMap.get(mockName1));
    BaseDataCache.getInstance().cachePluginData(pluginData);
    assertNotNull(pluginMap.get(mockName1));
    assertEquals(pluginData, pluginMap.get(mockName1));
}
Also used : PluginData(org.apache.shenyu.common.dto.PluginData) Test(org.junit.jupiter.api.Test)

Example 5 with PluginData

use of org.apache.shenyu.common.dto.PluginData in project incubator-shenyu by apache.

the class CommonPluginDataSubscriberTest method testUnSubscribe.

@Test
public void testUnSubscribe() {
    baseDataCache.cleanPluginData();
    PluginData pluginData = PluginData.builder().name(mockName1).build();
    baseDataCache.cachePluginData(pluginData);
    assertNotNull(baseDataCache.obtainPluginData(pluginData.getName()));
    commonPluginDataSubscriber.unSubscribe(pluginData);
    assertNull(baseDataCache.obtainPluginData(pluginData.getName()));
}
Also used : PluginData(org.apache.shenyu.common.dto.PluginData) Test(org.junit.jupiter.api.Test)

Aggregations

PluginData (org.apache.shenyu.common.dto.PluginData)69 Test (org.junit.jupiter.api.Test)41 RuleData (org.apache.shenyu.common.dto.RuleData)12 SelectorData (org.apache.shenyu.common.dto.SelectorData)12 PluginDataSubscriber (org.apache.shenyu.sync.data.api.PluginDataSubscriber)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ArrayList (java.util.ArrayList)6 Objects (java.util.Objects)6 AppAuthData (org.apache.shenyu.common.dto.AppAuthData)6 List (java.util.List)5 Optional (java.util.Optional)5 CollectionUtils (org.apache.commons.collections4.CollectionUtils)5 MetaData (org.apache.shenyu.common.dto.MetaData)5 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Splitter (com.google.common.base.Splitter)3 Lists (com.google.common.collect.Lists)3 JsonObject (com.google.gson.JsonObject)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URLDecoder (java.net.URLDecoder)3