Search in sources :

Example 6 with Instances

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());
}
Also used : Instances(com.alibaba.nacos.naming.core.Instances) Instance(com.alibaba.nacos.naming.core.Instance) Test(org.junit.Test)

Example 7 with Instances

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();
}
Also used : Instances(com.alibaba.nacos.naming.core.Instances) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Before(org.junit.Before)

Example 8 with Instances

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());
}
Also used : Instances(com.alibaba.nacos.naming.core.Instances) Datum(com.alibaba.nacos.naming.consistency.Datum) Instance(com.alibaba.nacos.naming.core.Instance) Test(org.junit.Test)

Example 9 with Instances

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"));
}
Also used : Instances(com.alibaba.nacos.naming.core.Instances) Instance(com.alibaba.nacos.naming.core.Instance) Before(org.junit.Before)

Example 10 with Instances

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());
}
Also used : Instances(com.alibaba.nacos.naming.core.Instances) Datum(com.alibaba.nacos.naming.consistency.Datum) Instance(com.alibaba.nacos.naming.core.Instance) Test(org.junit.Test) BaseTest(com.alibaba.nacos.naming.BaseTest)

Aggregations

Instances (com.alibaba.nacos.naming.core.Instances)10 Instance (com.alibaba.nacos.naming.core.Instance)6 Datum (com.alibaba.nacos.naming.consistency.Datum)5 Test (org.junit.Test)4 Service (com.alibaba.nacos.naming.core.Service)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Before (org.junit.Before)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 BaseTest (com.alibaba.nacos.naming.BaseTest)1 ConsistencyService (com.alibaba.nacos.naming.consistency.ConsistencyService)1 RaftPeer (com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeer)1 ServiceManager (com.alibaba.nacos.naming.core.ServiceManager)1 ServiceStorage (com.alibaba.nacos.naming.core.v2.index.ServiceStorage)1 ServiceChangeV2Task (com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV2Task)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1