use of com.alibaba.nacos.naming.core.Instances in project nacos by alibaba.
the class JacksonSerializerTest method testDeserialize.
@Test
@SuppressWarnings("checkstyle:linelength")
public void testDeserialize() {
String example = "{\"instanceList\":[{\"ip\":\"1.1.1.1\",\"port\":1234,\"weight\":1.0,\"healthy\":true,\"enabled\":true,\"ephemeral\":true,\"clusterName\":\"cluster\",\"metadata\":{},\"lastBeat\":1590563397264,\"marked\":false,\"instanceIdGenerator\":\"simple\",\"instanceHeartBeatInterval\":5000,\"instanceHeartBeatTimeOut\":15000,\"ipDeleteTimeout\":30000}]}";
Instances actual = serializer.deserialize(ByteUtils.toBytes(example), Instances.class);
assertEquals(1, actual.getInstanceList().size());
Instance actualInstance = actual.getInstanceList().get(0);
assertEquals("1.1.1.1", actualInstance.getIp());
assertEquals("cluster", actualInstance.getClusterName());
assertEquals(1234, actualInstance.getPort());
}
use of com.alibaba.nacos.naming.core.Instances in project nacos by alibaba.
the class DistroConsistencyServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
distroConsistencyService = new DistroConsistencyServiceImpl(distroMapper, dataStore, serializer, switchDomain, globalConfig, distroProtocol);
ReflectionTestUtils.setField(distroConsistencyService, "notifier", notifier);
ReflectionTestUtils.setField(distroConsistencyService, "distroProtocol", distroProtocol);
listeners = (Map<String, ConcurrentLinkedQueue<RecordListener>>) ReflectionTestUtils.getField(distroConsistencyService, "listeners");
instances = new Instances();
mockInjectUpgradeJudgement();
}
use of com.alibaba.nacos.naming.core.Instances in project nacos by alibaba.
the class JacksonSerializerTest method testDeserializeMap.
@Test
@SuppressWarnings("checkstyle:linelength")
public void testDeserializeMap() {
String example = "{\"datum\":{\"key\":\"instances\",\"value\":{\"instanceList\":[{\"ip\":\"1.1.1.1\",\"port\":1234,\"weight\":1.0,\"healthy\":true,\"enabled\":true,\"ephemeral\":true,\"clusterName\":\"cluster\",\"metadata\":{},\"lastBeat\":1590563397533,\"marked\":false,\"instanceIdGenerator\":\"simple\",\"instanceHeartBeatInterval\":5000,\"instanceHeartBeatTimeOut\":15000,\"ipDeleteTimeout\":30000}]},\"timestamp\":100000}}";
Map<String, Datum<Instances>> actual = serializer.deserializeMap(ByteUtils.toBytes(example), Instances.class);
assertEquals(actual.size(), 1);
assertTrue(actual.containsKey("datum"));
Datum<Instances> actualDatum = actual.get("datum");
assertEquals("instances", actualDatum.key);
assertEquals(100000L, actualDatum.timestamp.get());
assertEquals(1, actualDatum.value.getInstanceList().size());
Instance actualInstance = actualDatum.value.getInstanceList().get(0);
assertEquals("1.1.1.1", actualInstance.getIp());
assertEquals("cluster", actualInstance.getClusterName());
assertEquals(1234, actualInstance.getPort());
}
use of com.alibaba.nacos.naming.core.Instances in project nacos by alibaba.
the class JacksonSerializerTest method setUp.
@Before
public void setUp() throws Exception {
serializer = new JacksonSerializer();
instances = new Instances();
instances.getInstanceList().add(new Instance("1.1.1.1", 1234, "cluster"));
}
use of com.alibaba.nacos.naming.core.Instances in project nacos by alibaba.
the class RaftStoreTest method wrietDatum.
@Test
public void wrietDatum() throws Exception {
Datum<Instances> datum = new Datum<>();
String key = KeyBuilder.buildInstanceListKey(TEST_NAMESPACE, TEST_SERVICE_NAME, false);
datum.key = key;
datum.timestamp.getAndIncrement();
datum.value = new Instances();
Instance instance = new Instance("1.1.1.1", 1, TEST_CLUSTER_NAME);
datum.value.getInstanceList().add(instance);
instance = new Instance("2.2.2.2", 2, TEST_CLUSTER_NAME);
datum.value.getInstanceList().add(instance);
raftStore.write(datum);
raftCore.init();
Datum result = raftCore.getDatum(key);
Assert.assertEquals(key, result.key);
Assert.assertEquals(1, result.timestamp.intValue());
Assert.assertEquals(datum.value.toString(), result.value.toString());
}
Aggregations