Search in sources :

Example 1 with ServiceRegistration

use of io.scalecube.services.ServiceRegistration in project scalecube by scalecube.

the class ScalecubeServiceDiscoveryTest method testMetadataCodec.

@ParameterizedTest
@MethodSource("metadataCodecSource")
public void testMetadataCodec(MetadataCodec metadataCodec) {
    ServiceEndpoint serviceEndpoint = ServiceEndpoint.builder().id(UUID.randomUUID().toString()).tags(Collections.singletonMap("K", "V")).contentTypes(Collections.singleton("json")).appendServiceRegistrations(Collections.singletonList(new ServiceRegistration("namespace", Collections.singletonMap("KK", "VV"), Collections.singletonList(new ServiceMethodDefinition("action0", Collections.singletonMap("KKK0", "VVV"), true))))).appendServiceRegistrations(Collections.singletonList(new ServiceRegistration("namespace", Collections.singletonMap("KK", "VV"), Collections.singletonList(new ServiceMethodDefinition("action1", Collections.singletonMap("KKK1", "VVV"), true))))).appendServiceRegistrations(Collections.singletonList(new ServiceRegistration("namespace", Collections.singletonMap("KK", "VV"), Collections.singletonList(new ServiceMethodDefinition("action2", Collections.singletonMap("KKK2", "VVV"), true))))).build();
    ByteBuffer buffer = metadataCodec.serialize(serviceEndpoint);
    ServiceEndpoint serviceEndpoint1 = (ServiceEndpoint) metadataCodec.deserialize(buffer);
    Assertions.assertEquals(serviceEndpoint.id(), serviceEndpoint1.id());
    Assertions.assertEquals(1, serviceEndpoint1.tags().size());
    Assertions.assertEquals(1, serviceEndpoint1.contentTypes().size());
    List<ServiceRegistration> serviceRegistrations = new ArrayList<>(serviceEndpoint1.serviceRegistrations());
    Assertions.assertEquals(3, serviceRegistrations.size());
    for (ServiceRegistration serviceRegistration : serviceRegistrations) {
        Assertions.assertEquals(1, serviceRegistration.methods().size());
        Assertions.assertEquals(1, serviceRegistration.tags().size());
    }
}
Also used : ArrayList(java.util.ArrayList) ServiceMethodDefinition(io.scalecube.services.ServiceMethodDefinition) ByteBuffer(java.nio.ByteBuffer) ServiceEndpoint(io.scalecube.services.ServiceEndpoint) ServiceRegistration(io.scalecube.services.ServiceRegistration) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ServiceEndpoint (io.scalecube.services.ServiceEndpoint)1 ServiceMethodDefinition (io.scalecube.services.ServiceMethodDefinition)1 ServiceRegistration (io.scalecube.services.ServiceRegistration)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1