Search in sources :

Example 1 with ReplicationInstanceResponse

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

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

the class PeerReplicationResourceTest method assertStatusOkReply.

private static void assertStatusOkReply(Response httpResponse) {
    ReplicationListResponse entity = (ReplicationListResponse) httpResponse.getEntity();
    assertThat(entity, is(notNullValue()));
    ReplicationInstanceResponse replicationResponse = entity.getResponseList().get(0);
    assertThat(replicationResponse.getStatusCode(), is(equalTo(200)));
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse)

Example 3 with ReplicationInstanceResponse

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

the class EurekaCodecCompatibilityTest method testBatchResponseEncoding.

@Test
public void testBatchResponseEncoding() throws Exception {
    List<ReplicationInstanceResponse> responseList = new ArrayList<>();
    responseList.add(new ReplicationInstanceResponse(200, InstanceInfoGenerator.takeOne()));
    final ReplicationListResponse replicationListResponse = new ReplicationListResponse(responseList);
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(replicationListResponse);
            ReplicationListResponse decodedValue = decodingCodec.decode(encodedString, ReplicationListResponse.class);
            assertThat(decodedValue.getResponseList().size(), is(equalTo(1)));
        }
    };
    // In replication channel we use JSON only
    List<CodecWrapper> jsonCodes = Arrays.asList(new CodecWrappers.JacksonJson(), new CodecWrappers.LegacyJacksonJson());
    verifyAllPairs(codingAction, ReplicationListResponse.class, jsonCodes);
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) CodecWrapper(com.netflix.discovery.converters.wrappers.CodecWrapper) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ArrayList(java.util.ArrayList) 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 4 with ReplicationInstanceResponse

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

the class TestableHttpReplicationClient method submitBatchUpdates.

@Override
public EurekaHttpResponse<ReplicationListResponse> submitBatchUpdates(ReplicationList replicationList) {
    if (networkFailureCounter.get() < networkFailuresRepeatCount) {
        networkFailureCounter.incrementAndGet();
        throw new RuntimeException(new IOException("simulated network failure"));
    }
    if (processingDelayMs > 0) {
        try {
            Thread.sleep(processingDelayMs);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    List<ReplicationInstanceResponse> responseList = new ArrayList<>();
    responseList.add(new ReplicationInstanceResponse(batchStatusCode, instanceInfoFromPeer));
    ReplicationListResponse replicationListResponse = new ReplicationListResponse(responseList);
    handledRequests.add(new HandledRequest(RequestType.Batch, replicationList));
    int statusCode = networkStatusCodes[callCounter.getAndIncrement()];
    return anEurekaHttpResponse(statusCode, replicationListResponse).type(MediaType.APPLICATION_JSON_TYPE).build();
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

ReplicationInstanceResponse (com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse)4 ReplicationListResponse (com.netflix.eureka.cluster.protocol.ReplicationListResponse)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 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 ReplicationInstance (com.netflix.eureka.cluster.protocol.ReplicationInstance)1 ReplicationList (com.netflix.eureka.cluster.protocol.ReplicationList)1 IOException (java.io.IOException)1