本文整理汇总了Java中org.apache.curator.x.discovery.details.JsonInstanceSerializer.serialize方法的典型用法代码示例。如果您正苦于以下问题:Java JsonInstanceSerializer.serialize方法的具体用法?Java JsonInstanceSerializer.serialize怎么用?Java JsonInstanceSerializer.serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.x.discovery.details.JsonInstanceSerializer
的用法示例。
在下文中一共展示了JsonInstanceSerializer.serialize方法的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: registerServiceInstance
import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入方法依赖的package包/类
public void registerServiceInstance(String region,
String availabilityZone,
String flavor,
String serviceName,
int servicePort,
String serviceAddress,
String serviceAddressV6,
String weight) throws Exception {
String regPath = new StringBuilder().append(registrationPath).append("/").append(region).append("/")
.append(availabilityZone).append("/").append(flavor).toString();
ServiceInstance<MetaData> service = getServiceInstance(serviceName, servicePort, serviceAddress, new HashMap<String, String>() {{
put("ipv4Address", serviceAddress);
put("ipv6Address", serviceAddressV6);
if (weight != null) {
put("weight", weight);
}
}});
try {
JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<>(MetaData.class);
byte[] bytes = serializer.serialize(service);
String path = ZKPaths.makePath(ZKPaths.makePath(regPath, service.getName()), service.getId());
if ( ! connector.isPathExists(path)) {
connector.createEphemeral(path);
connector.save(new String(bytes), path);
} else {
log.warn("Node " + path + " already exists");
}
} catch (Exception e) {
e.printStackTrace();
}
}