Search in sources :

Example 1 with ReplicationInstance

use of com.netflix.eureka.cluster.protocol.ReplicationInstance in project eureka by Netflix.

the class EurekaCodecCompatibilityTest method testBatchRequestEncoding.

@Test
public void testBatchRequestEncoding() throws Exception {
    InstanceInfo instance = InstanceInfoGenerator.takeOne();
    List<ReplicationInstance> replicationInstances = new ArrayList<>();
    replicationInstances.add(new ReplicationInstance(instance.getAppName(), instance.getId(), System.currentTimeMillis(), null, instance.getStatus().name(), instance, Action.Register));
    final ReplicationList replicationList = new ReplicationList(replicationInstances);
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(replicationList);
            ReplicationList decodedValue = decodingCodec.decode(encodedString, ReplicationList.class);
            assertThat(decodedValue.getReplicationList().size(), is(equalTo(1)));
        }
    };
    // In replication channel we use JSON only
    List<CodecWrapper> jsonCodes = Arrays.asList(new CodecWrappers.JacksonJson(), new CodecWrappers.LegacyJacksonJson());
    verifyAllPairs(codingAction, ReplicationList.class, jsonCodes);
}
Also used : ReplicationInstance(com.netflix.eureka.cluster.protocol.ReplicationInstance) CodecWrapper(com.netflix.discovery.converters.wrappers.CodecWrapper) ArrayList(java.util.ArrayList) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 2 with ReplicationInstance

use of com.netflix.eureka.cluster.protocol.ReplicationInstance in project eureka by Netflix.

the class EurekaClientServerRestIntegrationTest method testBatch.

@Test
public void testBatch() throws Exception {
    InstanceInfo instanceInfo = instanceInfoIt.next();
    ReplicationInstance replicationInstance = ReplicationInstance.replicationInstance().withAction(Action.Register).withAppName(instanceInfo.getAppName()).withId(instanceInfo.getId()).withInstanceInfo(instanceInfo).withLastDirtyTimestamp(System.currentTimeMillis()).withStatus(instanceInfo.getStatus().name()).build();
    EurekaHttpResponse<ReplicationListResponse> httpResponse = jerseyReplicationClient.submitBatchUpdates(new ReplicationList(replicationInstance));
    assertThat(httpResponse.getStatusCode(), is(equalTo(200)));
    List<ReplicationInstanceResponse> replicationListResponse = httpResponse.getEntity().getResponseList();
    assertThat(replicationListResponse.size(), is(equalTo(1)));
    assertThat(replicationListResponse.get(0).getStatusCode(), is(equalTo(200)));
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) ReplicationInstance(com.netflix.eureka.cluster.protocol.ReplicationInstance) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 3 with ReplicationInstance

use of com.netflix.eureka.cluster.protocol.ReplicationInstance in project eureka by Netflix.

the class PeerReplicationResourceTest method testStatusUpdate.

@Test
public void testStatusUpdate() throws Exception {
    when(instanceResource.statusUpdate(anyString(), anyString(), anyString())).thenReturn(Response.ok().build());
    ReplicationInstance replicationInstance = newReplicationInstanceOf(Action.StatusUpdate, instanceInfo);
    Response response = peerReplicationResource.batchReplication(new ReplicationList(replicationInstance));
    assertStatusOkReply(response);
    verify(instanceResource, times(1)).statusUpdate(replicationInstance.getStatus(), "true", Long.toString(replicationInstance.getLastDirtyTimestamp()));
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) Response(javax.ws.rs.core.Response) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ReplicationInstance(com.netflix.eureka.cluster.protocol.ReplicationInstance) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList) Test(org.junit.Test)

Example 4 with ReplicationInstance

use of com.netflix.eureka.cluster.protocol.ReplicationInstance in project eureka by Netflix.

the class PeerEurekaNodeTest method testCancelBatchReplication.

@Test
public void testCancelBatchReplication() throws Exception {
    createPeerEurekaNode().cancel(instanceInfo.getAppName(), instanceInfo.getId());
    ReplicationInstance replicationInstance = expectSingleBatchRequest();
    assertThat(replicationInstance.getAction(), is(equalTo(Action.Cancel)));
}
Also used : ReplicationInstance(com.netflix.eureka.cluster.protocol.ReplicationInstance) Test(org.junit.Test)

Example 5 with ReplicationInstance

use of com.netflix.eureka.cluster.protocol.ReplicationInstance in project eureka by Netflix.

the class PeerEurekaNodeTest method testHeartbeatBatchReplication.

@Test
public void testHeartbeatBatchReplication() throws Throwable {
    createPeerEurekaNode().heartbeat(instanceInfo.getAppName(), instanceInfo.getId(), instanceInfo, null, false);
    ReplicationInstance replicationInstance = expectSingleBatchRequest();
    assertThat(replicationInstance.getAction(), is(equalTo(Action.Heartbeat)));
}
Also used : ReplicationInstance(com.netflix.eureka.cluster.protocol.ReplicationInstance) Test(org.junit.Test)

Aggregations

ReplicationInstance (com.netflix.eureka.cluster.protocol.ReplicationInstance)12 Test (org.junit.Test)11 ReplicationList (com.netflix.eureka.cluster.protocol.ReplicationList)6 ReplicationInstanceResponse (com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse)4 ReplicationListResponse (com.netflix.eureka.cluster.protocol.ReplicationListResponse)4 Response (javax.ws.rs.core.Response)3 InstanceInfo (com.netflix.appinfo.InstanceInfo)2 CodecWrapper (com.netflix.discovery.converters.wrappers.CodecWrapper)1 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)1 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)1 EncoderWrapper (com.netflix.discovery.converters.wrappers.EncoderWrapper)1 HandledRequest (com.netflix.eureka.cluster.TestableHttpReplicationClient.HandledRequest)1 ArrayList (java.util.ArrayList)1