Search in sources :

Example 1 with RegistryService

use of io.seata.discovery.registry.RegistryService in project seata by seata.

the class CustomRegistryTest method testCustomRegistryLoad.

@Test
public void testCustomRegistryLoad() {
    RegistryService registryService = RegistryFactory.getInstance();
    Assertions.assertTrue(registryService instanceof CustomRegistryServiceForTest);
}
Also used : RegistryService(io.seata.discovery.registry.RegistryService) Test(org.junit.jupiter.api.Test)

Example 2 with RegistryService

use of io.seata.discovery.registry.RegistryService in project seata by seata.

the class EtcdRegistryServiceImplTest method testRegister.

@Test
public void testRegister() throws Exception {
    RegistryService registryService = new EtcdRegistryProvider().provide();
    InetSocketAddress inetSocketAddress = new InetSocketAddress(HOST, PORT);
    // 1.register
    registryService.register(inetSocketAddress);
    // 2.get instance information
    GetOption getOption = GetOption.newBuilder().withPrefix(buildRegistryKeyPrefix()).build();
    long count = client.getKVClient().get(buildRegistryKeyPrefix(), getOption).get().getKvs().stream().filter(keyValue -> {
        String[] instanceInfo = keyValue.getValue().toString(UTF_8).split(":");
        return HOST.equals(instanceInfo[0]) && PORT == Integer.parseInt(instanceInfo[1]);
    }).count();
    assertThat(count).isEqualTo(1);
}
Also used : DeleteOption(io.etcd.jetcd.options.DeleteOption) GetOption(io.etcd.jetcd.options.GetOption) EtcdRegistryProvider(io.seata.discovery.registry.etcd3.EtcdRegistryProvider) Client(io.etcd.jetcd.Client) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Watch(io.etcd.jetcd.Watch) Disabled(org.junit.jupiter.api.Disabled) InetSocketAddress(java.net.InetSocketAddress) EtcdRegistryServiceImpl(io.seata.discovery.registry.etcd3.EtcdRegistryServiceImpl) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) WatchResponse(io.etcd.jetcd.watch.WatchResponse) Rule(org.junit.Rule) ByteSequence(io.etcd.jetcd.ByteSequence) BeforeAll(org.junit.jupiter.api.BeforeAll) DEFAULT_TX_GROUP(io.seata.common.DefaultValues.DEFAULT_TX_GROUP) UTF_8(io.netty.util.CharsetUtil.UTF_8) RegistryService(io.seata.discovery.registry.RegistryService) EtcdClusterResource(io.etcd.jetcd.launcher.junit.EtcdClusterResource) InetSocketAddress(java.net.InetSocketAddress) GetOption(io.etcd.jetcd.options.GetOption) EtcdRegistryProvider(io.seata.discovery.registry.etcd3.EtcdRegistryProvider) RegistryService(io.seata.discovery.registry.RegistryService) Test(org.junit.jupiter.api.Test)

Example 3 with RegistryService

use of io.seata.discovery.registry.RegistryService in project seata by seata.

the class EtcdRegistryServiceImplTest method testLookup.

@Test
public void testLookup() throws Exception {
    RegistryService registryService = new EtcdRegistryProvider().provide();
    InetSocketAddress inetSocketAddress = new InetSocketAddress(HOST, PORT);
    // 1.register
    registryService.register(inetSocketAddress);
    // 2.lookup
    List<InetSocketAddress> inetSocketAddresses = registryService.lookup(DEFAULT_TX_GROUP);
    assertThat(inetSocketAddresses).size().isEqualTo(1);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EtcdRegistryProvider(io.seata.discovery.registry.etcd3.EtcdRegistryProvider) RegistryService(io.seata.discovery.registry.RegistryService) Test(org.junit.jupiter.api.Test)

Example 4 with RegistryService

use of io.seata.discovery.registry.RegistryService in project seata by seata.

the class ConsulRegistryServiceImplTest method testRegister.

@Test
public void testRegister() throws Exception {
    RegistryService registryService = mock(ConsulRegistryServiceImpl.class);
    InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 8091);
    registryService.register(inetSocketAddress);
    verify(registryService).register(inetSocketAddress);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) RegistryService(io.seata.discovery.registry.RegistryService) Test(org.junit.jupiter.api.Test)

Example 5 with RegistryService

use of io.seata.discovery.registry.RegistryService in project seata by seata.

the class ConsulRegistryServiceImplTest method testLookup.

@Test
public void testLookup() throws Exception {
    RegistryService registryService = mock(ConsulRegistryServiceImpl.class);
    registryService.lookup("test-key");
    verify(registryService).lookup("test-key");
}
Also used : RegistryService(io.seata.discovery.registry.RegistryService) Test(org.junit.jupiter.api.Test)

Aggregations

RegistryService (io.seata.discovery.registry.RegistryService)14 InetSocketAddress (java.net.InetSocketAddress)11 Test (org.junit.jupiter.api.Test)10 EtcdRegistryProvider (io.seata.discovery.registry.etcd3.EtcdRegistryProvider)5 Disabled (org.junit.jupiter.api.Disabled)5 DeleteOption (io.etcd.jetcd.options.DeleteOption)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 ByteSequence (io.etcd.jetcd.ByteSequence)2 Client (io.etcd.jetcd.Client)2 Watch (io.etcd.jetcd.Watch)2 EtcdClusterResource (io.etcd.jetcd.launcher.junit.EtcdClusterResource)2 GetOption (io.etcd.jetcd.options.GetOption)2 WatchResponse (io.etcd.jetcd.watch.WatchResponse)2 UTF_8 (io.netty.util.CharsetUtil.UTF_8)2 DEFAULT_TX_GROUP (io.seata.common.DefaultValues.DEFAULT_TX_GROUP)2 EtcdRegistryServiceImpl (io.seata.discovery.registry.etcd3.EtcdRegistryServiceImpl)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2