Java Code Examples for org.apache.curator.x.discovery.details.JsonInstanceSerializer#serialize()
The following examples show how to use
org.apache.curator.x.discovery.details.JsonInstanceSerializer#serialize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestJsonInstanceSerializer.java From xian with Apache License 2.0 | 6 votes |
@Test public void testBasic() throws Exception { JsonInstanceSerializer<String> serializer = new JsonInstanceSerializer<String>(String.class); ServiceInstance<String> instance = new ServiceInstance<String>("name", "id", "address", 10, 20, "payload", 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), true); byte[] bytes = serializer.serialize(instance); ServiceInstance<String> rhs = serializer.deserialize(bytes); Assert.assertEquals(instance, rhs); Assert.assertEquals(instance.getId(), rhs.getId()); Assert.assertEquals(instance.getName(), rhs.getName()); Assert.assertEquals(instance.getPayload(), rhs.getPayload()); Assert.assertEquals(instance.getAddress(), rhs.getAddress()); Assert.assertEquals(instance.getPort(), rhs.getPort()); Assert.assertEquals(instance.getSslPort(), rhs.getSslPort()); Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec()); Assert.assertEquals(instance.isEnabled(), rhs.isEnabled()); }
Example 2
Source File: TestJsonInstanceSerializer.java From xian with Apache License 2.0 | 6 votes |
@Test public void testWrongPayloadType() throws Exception { JsonInstanceSerializer<String> stringSerializer = new JsonInstanceSerializer<String>(String.class); JsonInstanceSerializer<Double> doubleSerializer = new JsonInstanceSerializer<Double>(Double.class); byte[] bytes = stringSerializer.serialize(new ServiceInstance<String>("name", "id", "address", 10, 20, "payload", 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), true)); try { doubleSerializer.deserialize(bytes); Assert.fail(); } catch ( ClassCastException e ) { // correct } }
Example 3
Source File: TestJsonInstanceSerializer.java From xian with Apache License 2.0 | 6 votes |
@Test public void testNoPayload() throws Exception { JsonInstanceSerializer<Void> serializer = new JsonInstanceSerializer<Void>(Void.class); ServiceInstance<Void> instance = new ServiceInstance<Void>("name", "id", "address", 10, 20, null, 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), true); byte[] bytes = serializer.serialize(instance); ServiceInstance<Void> rhs = serializer.deserialize(bytes); Assert.assertEquals(instance, rhs); Assert.assertEquals(instance.getId(), rhs.getId()); Assert.assertEquals(instance.getName(), rhs.getName()); Assert.assertEquals(instance.getPayload(), rhs.getPayload()); Assert.assertEquals(instance.getAddress(), rhs.getAddress()); Assert.assertEquals(instance.getPort(), rhs.getPort()); Assert.assertEquals(instance.getSslPort(), rhs.getSslPort()); Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec()); Assert.assertEquals(instance.isEnabled(), rhs.isEnabled()); }
Example 4
Source File: TestJsonInstanceSerializer.java From xian with Apache License 2.0 | 6 votes |
@Test public void testPayloadAsList() throws Exception { JsonInstanceSerializer<Object> serializer = new JsonInstanceSerializer<Object>(Object.class); List<String> payload = new ArrayList<String>(); payload.add("Test value 1"); payload.add("Test value 2"); ServiceInstance<Object> instance = new ServiceInstance<Object>("name", "id", "address", 10, 20, payload, 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), false); byte[] bytes = serializer.serialize(instance); ServiceInstance<Object> rhs = serializer.deserialize(bytes); Assert.assertEquals(instance, rhs); Assert.assertEquals(instance.getId(), rhs.getId()); Assert.assertEquals(instance.getName(), rhs.getName()); Assert.assertEquals(instance.getPayload(), rhs.getPayload()); Assert.assertEquals(instance.getAddress(), rhs.getAddress()); Assert.assertEquals(instance.getPort(), rhs.getPort()); Assert.assertEquals(instance.getSslPort(), rhs.getSslPort()); Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec()); Assert.assertEquals(instance.isEnabled(), rhs.isEnabled()); }
Example 5
Source File: TestJsonInstanceSerializer.java From xian with Apache License 2.0 | 6 votes |
@Test public void testPayloadAsMap() throws Exception { JsonInstanceSerializer<Object> serializer = new JsonInstanceSerializer<Object>(Object.class); Map<String,String> payload = new HashMap<String,String>(); payload.put("1", "Test value 1"); payload.put("2", "Test value 2"); ServiceInstance<Object> instance = new ServiceInstance<Object>("name", "id", "address", 10, 20, payload, 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), false); byte[] bytes = serializer.serialize(instance); ServiceInstance<Object> rhs = serializer.deserialize(bytes); Assert.assertEquals(instance, rhs); Assert.assertEquals(instance.getId(), rhs.getId()); Assert.assertEquals(instance.getName(), rhs.getName()); Assert.assertEquals(instance.getPayload(), rhs.getPayload()); Assert.assertEquals(instance.getAddress(), rhs.getAddress()); Assert.assertEquals(instance.getPort(), rhs.getPort()); Assert.assertEquals(instance.getSslPort(), rhs.getSslPort()); Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec()); Assert.assertEquals(instance.isEnabled(), rhs.isEnabled()); }
Example 6
Source File: TestJsonInstanceSerializer.java From xian with Apache License 2.0 | 6 votes |
@Test public void testPayloadClass() throws Exception { JsonInstanceSerializer<Payload> serializer = new JsonInstanceSerializer<Payload>(Payload.class); Payload payload = new Payload(); payload.setVal("Test value"); ServiceInstance<Payload> instance = new ServiceInstance<Payload>("name", "id", "address", 10, 20, payload, 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), true); byte[] bytes = serializer.serialize(instance); ServiceInstance<Payload> rhs = serializer.deserialize(bytes); Assert.assertEquals(instance, rhs); Assert.assertEquals(instance.getId(), rhs.getId()); Assert.assertEquals(instance.getName(), rhs.getName()); Assert.assertEquals(instance.getPayload(), rhs.getPayload()); Assert.assertEquals(instance.getAddress(), rhs.getAddress()); Assert.assertEquals(instance.getPort(), rhs.getPort()); Assert.assertEquals(instance.getSslPort(), rhs.getSslPort()); Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec()); Assert.assertEquals(instance.isEnabled(), rhs.isEnabled()); }
Example 7
Source File: TestJsonInstanceSerializer.java From curator with Apache License 2.0 | 6 votes |
@Test public void testBasic() throws Exception { JsonInstanceSerializer<String> serializer = new JsonInstanceSerializer<String>(String.class); ServiceInstance<String> instance = new ServiceInstance<String>("name", "id", "address", 10, 20, "payload", 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), true); byte[] bytes = serializer.serialize(instance); ServiceInstance<String> rhs = serializer.deserialize(bytes); Assert.assertEquals(instance, rhs); Assert.assertEquals(instance.getId(), rhs.getId()); Assert.assertEquals(instance.getName(), rhs.getName()); Assert.assertEquals(instance.getPayload(), rhs.getPayload()); Assert.assertEquals(instance.getAddress(), rhs.getAddress()); Assert.assertEquals(instance.getPort(), rhs.getPort()); Assert.assertEquals(instance.getSslPort(), rhs.getSslPort()); Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec()); Assert.assertEquals(instance.isEnabled(), rhs.isEnabled()); }
Example 8
Source File: TestJsonInstanceSerializer.java From curator with Apache License 2.0 | 6 votes |
@Test public void testWrongPayloadType() throws Exception { JsonInstanceSerializer<String> stringSerializer = new JsonInstanceSerializer<String>(String.class); JsonInstanceSerializer<Double> doubleSerializer = new JsonInstanceSerializer<Double>(Double.class); byte[] bytes = stringSerializer.serialize(new ServiceInstance<String>("name", "id", "address", 10, 20, "payload", 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), true)); try { doubleSerializer.deserialize(bytes); Assert.fail(); } catch ( ClassCastException e ) { // correct } }
Example 9
Source File: TestJsonInstanceSerializer.java From curator with Apache License 2.0 | 6 votes |
@Test public void testNoPayload() throws Exception { JsonInstanceSerializer<Void> serializer = new JsonInstanceSerializer<Void>(Void.class); ServiceInstance<Void> instance = new ServiceInstance<Void>("name", "id", "address", 10, 20, null, 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), true); byte[] bytes = serializer.serialize(instance); ServiceInstance<Void> rhs = serializer.deserialize(bytes); Assert.assertEquals(instance, rhs); Assert.assertEquals(instance.getId(), rhs.getId()); Assert.assertEquals(instance.getName(), rhs.getName()); Assert.assertEquals(instance.getPayload(), rhs.getPayload()); Assert.assertEquals(instance.getAddress(), rhs.getAddress()); Assert.assertEquals(instance.getPort(), rhs.getPort()); Assert.assertEquals(instance.getSslPort(), rhs.getSslPort()); Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec()); Assert.assertEquals(instance.isEnabled(), rhs.isEnabled()); }
Example 10
Source File: TestJsonInstanceSerializer.java From curator with Apache License 2.0 | 6 votes |
@Test public void testPayloadAsList() throws Exception { JsonInstanceSerializer<Object> serializer = new JsonInstanceSerializer<Object>(Object.class, false); List<String> payload = new ArrayList<String>(); payload.add("Test value 1"); payload.add("Test value 2"); ServiceInstance<Object> instance = new ServiceInstance<Object>("name", "id", "address", 10, 20, payload, 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), false); byte[] bytes = serializer.serialize(instance); ServiceInstance<Object> rhs = serializer.deserialize(bytes); Assert.assertEquals(instance, rhs); Assert.assertEquals(instance.getId(), rhs.getId()); Assert.assertEquals(instance.getName(), rhs.getName()); Assert.assertEquals(instance.getPayload(), rhs.getPayload()); Assert.assertEquals(instance.getAddress(), rhs.getAddress()); Assert.assertEquals(instance.getPort(), rhs.getPort()); Assert.assertEquals(instance.getSslPort(), rhs.getSslPort()); Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec()); Assert.assertEquals(instance.isEnabled(), rhs.isEnabled()); }
Example 11
Source File: TestJsonInstanceSerializer.java From curator with Apache License 2.0 | 6 votes |
@Test public void testPayloadAsMap() throws Exception { JsonInstanceSerializer<Object> serializer = new JsonInstanceSerializer<Object>(Object.class, false); Map<String,String> payload = new HashMap<String,String>(); payload.put("1", "Test value 1"); payload.put("2", "Test value 2"); ServiceInstance<Object> instance = new ServiceInstance<Object>("name", "id", "address", 10, 20, payload, 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), false); byte[] bytes = serializer.serialize(instance); ServiceInstance<Object> rhs = serializer.deserialize(bytes); Assert.assertEquals(instance, rhs); Assert.assertEquals(instance.getId(), rhs.getId()); Assert.assertEquals(instance.getName(), rhs.getName()); Assert.assertEquals(instance.getPayload(), rhs.getPayload()); Assert.assertEquals(instance.getAddress(), rhs.getAddress()); Assert.assertEquals(instance.getPort(), rhs.getPort()); Assert.assertEquals(instance.getSslPort(), rhs.getSslPort()); Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec()); Assert.assertEquals(instance.isEnabled(), rhs.isEnabled()); }
Example 12
Source File: TestJsonInstanceSerializer.java From curator with Apache License 2.0 | 6 votes |
@Test public void testPayloadClass() throws Exception { JsonInstanceSerializer<Payload> serializer = new JsonInstanceSerializer<Payload>(Payload.class); Payload payload = new Payload(); payload.setVal("Test value"); ServiceInstance<Payload> instance = new ServiceInstance<Payload>("name", "id", "address", 10, 20, payload, 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), true); byte[] bytes = serializer.serialize(instance); ServiceInstance<Payload> rhs = serializer.deserialize(bytes); Assert.assertEquals(instance, rhs); Assert.assertEquals(instance.getId(), rhs.getId()); Assert.assertEquals(instance.getName(), rhs.getName()); Assert.assertEquals(instance.getPayload(), rhs.getPayload()); Assert.assertEquals(instance.getAddress(), rhs.getAddress()); Assert.assertEquals(instance.getPort(), rhs.getPort()); Assert.assertEquals(instance.getSslPort(), rhs.getSslPort()); Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec()); Assert.assertEquals(instance.isEnabled(), rhs.isEnabled()); }