use of org.apache.servicecomb.serviceregistry.ServiceRegistry in project incubator-servicecomb-java-chassis by apache.
the class TestLocalServiceRegistry method testUpdateProperties.
@Test
public void testUpdateProperties() {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
serviceRegistry.run();
Microservice microservice = serviceRegistry.getMicroservice();
Map<String, String> properties = new HashMap<>();
properties.put("k", "v");
try {
serviceRegistry.getServiceRegistryClient().updateInstanceProperties(microservice.getServiceId(), "notExist", properties);
Assert.fail("must throw exception");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Invalid argument. microserviceId=" + microservice.getServiceId() + ", microserviceInstanceId=notExist.", e.getMessage());
}
serviceRegistry.updateMicroserviceProperties(properties);
Assert.assertEquals(properties, microservice.getProperties());
serviceRegistry.updateInstanceProperties(properties);
Assert.assertEquals(properties, microservice.getInstance().getProperties());
properties.put("k1", "v1");
serviceRegistry.updateMicroserviceProperties(properties);
Assert.assertEquals(properties, microservice.getProperties());
serviceRegistry.updateInstanceProperties(properties);
Assert.assertEquals(properties, microservice.getInstance().getProperties());
}
use of org.apache.servicecomb.serviceregistry.ServiceRegistry in project incubator-servicecomb-java-chassis by apache.
the class TestServiceRegistryFactory method testGetRemoteRegistryClient.
@Test
public void testGetRemoteRegistryClient() {
EventBus eventBus = new EventBus();
ServiceRegistryConfig serviceRegistryConfig = ServiceRegistryConfig.INSTANCE;
MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(Collections.emptyList());
ServiceRegistry serviceRegistry = ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, microserviceDefinition);
serviceRegistry.init();
ServiceRegistryClient client = serviceRegistry.getServiceRegistryClient();
Assert.assertTrue(client instanceof ServiceRegistryClientImpl);
serviceRegistry = ServiceRegistryFactory.getOrCreate(eventBus, serviceRegistryConfig, microserviceDefinition);
Assert.assertTrue(serviceRegistry instanceof RemoteServiceRegistry);
Assert.assertEquals(serviceRegistry, ServiceRegistryFactory.getServiceRegistry());
Deencapsulation.setField(ServiceRegistryFactory.class, "serviceRegistry", null);
System.setProperty("local.registry.file", "/tmp/test.yaml");
serviceRegistry = ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, microserviceDefinition);
serviceRegistry.init();
client = serviceRegistry.getServiceRegistryClient();
Assert.assertTrue(client instanceof LocalServiceRegistryClientImpl);
Assert.assertTrue(ServiceRegistryFactory.getOrCreate(eventBus, serviceRegistryConfig, microserviceDefinition) instanceof LocalServiceRegistry);
System.clearProperty("local.registry.file");
}
use of org.apache.servicecomb.serviceregistry.ServiceRegistry in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayCodec method setUp.
@Before
public void setUp() throws Exception {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
RegistryUtils.setServiceRegistry(serviceRegistry);
header = Mockito.mock(RequestHeader.class);
operationProtobuf = Mockito.mock(OperationProtobuf.class);
bodyBuffer = Mockito.mock(Buffer.class);
schema = Mockito.mock(WrapSchema.class);
schemaMeta = Mockito.mock(SchemaMeta.class);
operationMeta = Mockito.mock(OperationMeta.class);
lByteBuf = Mockito.mock(ByteBuf.class);
nioBuffer = Mockito.mock(ByteBuffer.class);
invocation = Mockito.mock(Invocation.class);
}
use of org.apache.servicecomb.serviceregistry.ServiceRegistry in project incubator-servicecomb-java-chassis by apache.
the class TestDynamicSchemaLoader method init.
@BeforeClass
public static void init() {
UnitTestMeta.init();
loader.setMicroserviceMetaManager(microserviceMetaManager);
SchemaListenerManager schemaListenerManager = new SchemaListenerManager();
schemaListenerManager.setSchemaListenerList(Collections.emptyList());
CseContext context = CseContext.getInstance();
context.setSchemaLoader(loader);
context.setSchemaListenerManager(schemaListenerManager);
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
microservice = serviceRegistry.getMicroservice();
RegistryUtils.setServiceRegistry(serviceRegistry);
}
use of org.apache.servicecomb.serviceregistry.ServiceRegistry in project incubator-servicecomb-java-chassis by apache.
the class TestProducerSchemaFactory method init.
@BeforeClass
public static void init() {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
RegistryUtils.setServiceRegistry(serviceRegistry);
ConverterMgr converterMgr = new ConverterMgr();
ProducerArgumentsMapperFactory producerArgsMapperFactory = new ProducerArgumentsMapperFactory();
producerArgsMapperFactory.setConverterMgr(converterMgr);
MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
SchemaLoader schemaLoader = new SchemaLoader() {
@Override
public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
}
};
CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
producerSchemaFactory.setSwaggerEnv(swaggerEnv);
ReflectUtils.setField(producerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
ReflectUtils.setField(producerSchemaFactory, "schemaLoader", schemaLoader);
ReflectUtils.setField(producerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
Executor reactiveExecutor = new ReactiveExecutor();
Executor normalExecutor = (cmd) -> {
};
new MockUp<BeanUtils>() {
@SuppressWarnings("unchecked")
@Mock
<T> T getBean(String name) {
if (ExecutorManager.EXECUTOR_REACTIVE.equals(name)) {
return (T) reactiveExecutor;
}
return (T) normalExecutor;
}
};
// ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
// BeanUtils.setContext(applicationContext);
// Mockito.when(applicationContext.getBean(ExecutorManager.EXECUTOR_REACTIVE)).thenReturn(new ReactiveExecutor());
UnitTestMeta.init();
schemaMeta = producerSchemaFactory.getOrCreateProducerSchema("app:ms", "schema", TestProducerSchemaFactoryImpl.class, new TestProducerSchemaFactoryImpl());
}
Aggregations