Search in sources :

Example 1 with ReplicationList

use of com.netflix.eureka.cluster.protocol.ReplicationList 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 2 with ReplicationList

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

the class PeerReplicationResourceTest method testRegisterBatching.

@Test
public void testRegisterBatching() throws Exception {
    ReplicationList replicationList = new ReplicationList(newReplicationInstanceOf(Action.Register, instanceInfo));
    Response response = peerReplicationResource.batchReplication(replicationList);
    assertStatusOkReply(response);
    verify(applicationResource, times(1)).addInstance(instanceInfo, "true");
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) Response(javax.ws.rs.core.Response) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList) Test(org.junit.Test)

Example 3 with ReplicationList

use of com.netflix.eureka.cluster.protocol.ReplicationList 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 ReplicationList

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

the class PeerEurekaNodeTest method expectSingleBatchRequest.

private ReplicationInstance expectSingleBatchRequest() throws InterruptedException {
    HandledRequest handledRequest = httpReplicationClient.nextHandledRequest(30, TimeUnit.SECONDS);
    assertThat(handledRequest, is(notNullValue()));
    assertThat(handledRequest.getRequestType(), is(equalTo(RequestType.Batch)));
    Object data = handledRequest.getData();
    assertThat(data, is(instanceOf(ReplicationList.class)));
    List<ReplicationInstance> replications = ((ReplicationList) data).getReplicationList();
    assertThat(replications.size(), is(equalTo(1)));
    return replications.get(0);
}
Also used : ReplicationInstance(com.netflix.eureka.cluster.protocol.ReplicationInstance) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList) HandledRequest(com.netflix.eureka.cluster.TestableHttpReplicationClient.HandledRequest)

Example 5 with ReplicationList

use of com.netflix.eureka.cluster.protocol.ReplicationList 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)

Aggregations

ReplicationList (com.netflix.eureka.cluster.protocol.ReplicationList)10 ReplicationListResponse (com.netflix.eureka.cluster.protocol.ReplicationListResponse)8 Test (org.junit.Test)8 ReplicationInstance (com.netflix.eureka.cluster.protocol.ReplicationInstance)7 ReplicationInstanceResponse (com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse)7 Response (javax.ws.rs.core.Response)6 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