use of com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager in project nacos by alibaba.
the class ServiceStorageTest method setUp.
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
serviceStorage = new ServiceStorage(clientServiceIndexesManager, clientManagerDelegate, switchDomain, namingMetadataManager);
Field serviceClusterIndex = ServiceStorage.class.getDeclaredField("serviceClusterIndex");
serviceClusterIndex.setAccessible(true);
ConcurrentMap<Service, Set<String>> serviceSetConcurrentMap = (ConcurrentMap<Service, Set<String>>) serviceClusterIndex.get(serviceStorage);
serviceSetConcurrentMap.put(SERVICE, new HashSet<>(Collections.singletonList(NACOS)));
Field serviceDataIndexes = ServiceStorage.class.getDeclaredField("serviceDataIndexes");
serviceDataIndexes.setAccessible(true);
ConcurrentMap<Service, ServiceInfo> infoConcurrentMap = (ConcurrentMap<Service, ServiceInfo>) serviceDataIndexes.get(serviceStorage);
infoConcurrentMap.put(SERVICE, serviceInfo);
}
use of com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager in project nacos by alibaba.
the class ClientServiceIndexesManagerTest method setUp.
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
clientServiceIndexesManager = new ClientServiceIndexesManager();
Class<ClientServiceIndexesManager> clientServiceIndexesManagerClass = ClientServiceIndexesManager.class;
Field publisherIndexesField = clientServiceIndexesManagerClass.getDeclaredField("publisherIndexes");
publisherIndexesField.setAccessible(true);
ConcurrentMap<Service, Set<String>> publisherIndexes = (ConcurrentMap<Service, Set<String>>) publisherIndexesField.get(clientServiceIndexesManager);
publisherIndexes.put(service, new HashSet<>(Collections.singletonList(NACOS)));
Field subscriberIndexesField = clientServiceIndexesManagerClass.getDeclaredField("subscriberIndexes");
subscriberIndexesField.setAccessible(true);
ConcurrentMap<Service, Set<String>> subscriberIndexes = (ConcurrentMap<Service, Set<String>>) subscriberIndexesField.get(clientServiceIndexesManager);
subscriberIndexes.put(service, new HashSet<>(Collections.singletonList(NACOS)));
}
use of com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager in project nacos by alibaba.
the class EmptyServiceAutoCleanerV2Test method setUp.
@Before
public void setUp() {
EnvUtil.setEnvironment(new MockEnvironment());
emptyServiceAutoCleanerV2 = new EmptyServiceAutoCleanerV2(clientServiceIndexesManager, serviceStorage);
Mockito.when(service.getNamespace()).thenReturn("public");
ServiceManager serviceManager = ServiceManager.getInstance();
serviceManager.getSingleton(service);
}
use of com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager in project nacos by alibaba.
the class DoubleWriteServiceRemovalToV2Task method run.
@Override
public void run() {
try {
InstanceOperatorClientImpl instanceOperator = ApplicationUtils.getBean(InstanceOperatorClientImpl.class);
ClientServiceIndexesManager clientServiceIndexesManager = ApplicationUtils.getBean(ClientServiceIndexesManager.class);
ServiceStorage serviceStorage = ApplicationUtils.getBean(ServiceStorage.class);
ServiceInfo serviceInfo = serviceStorage.getPushData(service);
for (Instance instance : serviceInfo.getHosts()) {
instanceOperator.removeInstance(service.getNamespace(), service.getName(), instance);
}
int count = 0;
while (!clientServiceIndexesManager.getAllClientsRegisteredService(service).isEmpty() && count < MAX_WAIT_TIMES) {
TimeUnit.MILLISECONDS.sleep(100);
count += 1;
}
clientServiceIndexesManager.removePublisherIndexesByEmptyService(service);
ServiceManager.getInstance().removeSingleton(service);
serviceStorage.removeData(service);
NotifyCenter.publishEvent(new MetadataEvent.ServiceMetadataEvent(service, true));
} catch (Exception e) {
if (Loggers.SRV_LOG.isDebugEnabled()) {
Loggers.SRV_LOG.debug("Double write removal of {} from 1 to 2 failed", service, e);
}
ServiceChangeV1Task retryTask = new ServiceChangeV1Task(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral(), DoubleWriteContent.BOTH, DoubleWriteAction.REMOVE);
retryTask.setTaskInterval(INTERVAL);
String taskKey = ServiceChangeV1Task.getKey(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral());
ApplicationUtils.getBean(DoubleWriteDelayTaskEngine.class).addTask(taskKey, retryTask);
}
}
use of com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager in project nacos by alibaba.
the class ClientServiceIndexesManagerTest method testRemovePublisherIndexesByEmptyService.
@Test
public void testRemovePublisherIndexesByEmptyService() throws NoSuchFieldException, IllegalAccessException {
clientServiceIndexesManager.removePublisherIndexesByEmptyService(service);
Class<ClientServiceIndexesManager> clientServiceIndexesManagerClass = ClientServiceIndexesManager.class;
Field publisherIndexesField = clientServiceIndexesManagerClass.getDeclaredField("publisherIndexes");
publisherIndexesField.setAccessible(true);
ConcurrentMap<Service, Set<String>> publisherIndexes = (ConcurrentMap<Service, Set<String>>) publisherIndexesField.get(clientServiceIndexesManager);
Assert.assertEquals(publisherIndexes.size(), 1);
}
Aggregations