use of com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager in project nacos by alibaba.
the class ServiceMetadataProcessorTest method testOnApply.
@Test
public void testOnApply() throws NoSuchFieldException, IllegalAccessException {
WriteRequest defaultInstance = WriteRequest.getDefaultInstance();
Class<WriteRequest> writeRequestClass = WriteRequest.class;
Field operation = writeRequestClass.getDeclaredField("operation_");
operation.setAccessible(true);
operation.set(defaultInstance, "ADD");
MetadataOperation<ServiceMetadata> metadataOperation = new MetadataOperation<>();
ServiceMetadata serviceMetadata = new ServiceMetadata();
metadataOperation.setMetadata(serviceMetadata);
metadataOperation.setServiceName("nacos");
metadataOperation.setNamespace("namespace");
metadataOperation.setGroup("group");
Serializer aDefault = SerializeFactory.getDefault();
ByteString bytes = ByteString.copyFrom(aDefault.serialize(metadataOperation));
Field data = writeRequestClass.getDeclaredField("data_");
data.setAccessible(true);
data.set(defaultInstance, bytes);
// ADD
Response addResponse = serviceMetadataProcessor.onApply(defaultInstance);
Service service = Service.newService(metadataOperation.getNamespace(), metadataOperation.getGroup(), metadataOperation.getServiceName(), metadataOperation.getMetadata().isEphemeral());
Service singleton = ServiceManager.getInstance().getSingleton(service);
namingMetadataManager.updateServiceMetadata(singleton, metadataOperation.getMetadata());
Assert.assertTrue(addResponse.getSuccess());
verify(namingMetadataManager).getServiceMetadata(service);
verify(namingMetadataManager).updateServiceMetadata(service, serviceMetadata);
verify(context).getBean(DoubleWriteEventListener.class);
// CHANGE
operation.set(defaultInstance, "CHANGE");
Response changeResponse = serviceMetadataProcessor.onApply(defaultInstance);
Assert.assertTrue(changeResponse.getSuccess());
verify(namingMetadataManager, times(2)).getServiceMetadata(service);
verify(namingMetadataManager).updateServiceMetadata(service, serviceMetadata);
verify(context, times(2)).getBean(DoubleWriteEventListener.class);
// DELETE
operation.set(defaultInstance, "DELETE");
Response deleteResponse = serviceMetadataProcessor.onApply(defaultInstance);
Assert.assertTrue(deleteResponse.getSuccess());
verify(namingMetadataManager).removeServiceMetadata(service);
verify(serviceStorage).removeData(service);
// VERIFY
operation.set(defaultInstance, "VERIFY");
Response otherResponse = serviceMetadataProcessor.onApply(defaultInstance);
Assert.assertFalse(otherResponse.getSuccess());
}
use of com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager in project nacos by alibaba.
the class NamingMetadataManagerTest method setUp.
@Before
public void setUp() throws Exception {
namingMetadataManager = new NamingMetadataManager();
Class<NamingMetadataManager> namingMetadataManagerClass = NamingMetadataManager.class;
Field serviceMetadataMapField = namingMetadataManagerClass.getDeclaredField("serviceMetadataMap");
serviceMetadataMapField.setAccessible(true);
ConcurrentMap<Service, ServiceMetadata> serviceMetadataMap = (ConcurrentMap<Service, ServiceMetadata>) serviceMetadataMapField.get(namingMetadataManager);
serviceMetadataMap.put(service, serviceMetadata);
Field instanceMetadataMapField = namingMetadataManagerClass.getDeclaredField("instanceMetadataMap");
instanceMetadataMapField.setAccessible(true);
ConcurrentMap<Service, ConcurrentMap<String, InstanceMetadata>> instanceMetadataMap = (ConcurrentMap<Service, ConcurrentMap<String, InstanceMetadata>>) instanceMetadataMapField.get(namingMetadataManager);
ConcurrentMap<String, InstanceMetadata> concurrentMap = new ConcurrentHashMap<>();
concurrentMap.put(METADATA_ID, instanceMetadata);
instanceMetadataMap.put(service, concurrentMap);
}
use of com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager in project nacos by alibaba.
the class ClientBeatCheckTaskV2Test method setUp.
@Before
public void setUp() throws Exception {
when(applicationContext.getBean(NamingMetadataManager.class)).thenReturn(namingMetadataManager);
when(applicationContext.getBean(GlobalConfig.class)).thenReturn(globalConfig);
when(applicationContext.getBean(DistroMapper.class)).thenReturn(distroMapper);
when(distroMapper.responsible(anyString())).thenReturn(true);
ApplicationUtils.injectContext(applicationContext);
client = new IpPortBasedClient(CLIENT_ID, true);
beatCheckTask = new ClientBeatCheckTaskV2(client);
}
use of com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager in project nacos by alibaba.
the class HealthCheckTaskV2Test method setUp.
@Before
public void setUp() {
ApplicationUtils.injectContext(context);
when(ApplicationUtils.getBean(SwitchDomain.class)).thenReturn(switchDomain);
when(switchDomain.getTcpHealthParams()).thenReturn(new SwitchDomain.TcpHealthParams());
when(ApplicationUtils.getBean(NamingMetadataManager.class)).thenReturn(new NamingMetadataManager());
healthCheckTaskV2 = new HealthCheckTaskV2(ipPortBasedClient);
}
Aggregations