本文整理汇总了Java中org.apache.curator.x.discovery.details.JsonInstanceSerializer.deserialize方法的典型用法代码示例。如果您正苦于以下问题:Java JsonInstanceSerializer.deserialize方法的具体用法?Java JsonInstanceSerializer.deserialize怎么用?Java JsonInstanceSerializer.deserialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.x.discovery.details.JsonInstanceSerializer
的用法示例。
在下文中一共展示了JsonInstanceSerializer.deserialize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBasic
import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入方法依赖的package包/类
@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());
}
示例2: testWrongPayloadType
import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入方法依赖的package包/类
@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
}
}
示例3: testNoPayload
import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入方法依赖的package包/类
@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());
}
示例4: UriSpec
import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入方法依赖的package包/类
@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());
}
示例5: Payload
import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入方法依赖的package包/类
@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());
}
示例6: testNoEnabledState
import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入方法依赖的package包/类
@Test
public void testNoEnabledState() throws Exception
{
JsonInstanceSerializer<Void> serializer = new JsonInstanceSerializer<Void>(Void.class);
byte[] bytes = "{}".getBytes("utf-8");
ServiceInstance<Void> instance = serializer.deserialize(bytes);
Assert.assertTrue(instance.isEnabled(), "Instance that has no 'enabled' should be assumed enabled");
}