Search in sources :

Example 86 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class EurekaEventListenerTest method testCacheRefreshEvent.

@Test
public void testCacheRefreshEvent() throws Exception {
    CapturingEurekaEventListener listener = new CapturingEurekaEventListener();
    Applications initialApps = toApplications(discoveryClientResource.getMyInstanceInfo());
    when(requestHandler.getApplications()).thenReturn(anEurekaHttpResponse(200, initialApps).type(MediaType.APPLICATION_JSON_TYPE).build());
    DiscoveryClient client = (DiscoveryClient) discoveryClientResource.getClient();
    client.registerEventListener(listener);
    client.refreshRegistry();
    assertNotNull(listener.event);
    assertThat(listener.event, is(instanceOf(CacheRefreshedEvent.class)));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) Test(org.junit.Test)

Example 87 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class EurekaJacksonCodecTest method testApplicationsJacksonEncodeXStreamDecode.

@Test
public void testApplicationsJacksonEncodeXStreamDecode() throws Exception {
    // Encode
    ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
    codec.writeTo(APPLICATIONS, captureStream);
    byte[] encoded = captureStream.toByteArray();
    // Decode
    InputStream source = new ByteArrayInputStream(encoded);
    Applications decoded = (Applications) new EntityBodyConverter().read(source, Applications.class, MediaType.APPLICATION_JSON_TYPE);
    assertTrue(EurekaEntityComparators.equal(decoded, APPLICATIONS));
}
Also used : Applications(com.netflix.discovery.shared.Applications) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 88 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class EurekaJacksonCodecTest method testApplicationsJacksonEncodeDecode.

@Test
public void testApplicationsJacksonEncodeDecode() throws Exception {
    // Encode
    ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
    codec.writeTo(APPLICATIONS, captureStream);
    byte[] encoded = captureStream.toByteArray();
    // Decode
    InputStream source = new ByteArrayInputStream(encoded);
    Applications decoded = codec.readValue(Applications.class, source);
    assertTrue(EurekaEntityComparators.equal(decoded, APPLICATIONS));
}
Also used : Applications(com.netflix.discovery.shared.Applications) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 89 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class EurekaJacksonCodecTest method testApplicationsXStreamEncodeJacksonDecode.

@Test
public void testApplicationsXStreamEncodeJacksonDecode() throws Exception {
    Applications original = APPLICATIONS;
    // Encode
    ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
    new EntityBodyConverter().write(original, captureStream, MediaType.APPLICATION_JSON_TYPE);
    byte[] encoded = captureStream.toByteArray();
    String encodedString = new String(encoded);
    // Decode
    InputStream source = new ByteArrayInputStream(encoded);
    Applications decoded = codec.readValue(Applications.class, source);
    assertTrue(EurekaEntityComparators.equal(decoded, original));
}
Also used : Applications(com.netflix.discovery.shared.Applications) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 90 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class JsonXStreamTest method testEncodingDecodingWithoutMetaData.

@Test
public void testEncodingDecodingWithoutMetaData() throws Exception {
    Applications applications = InstanceInfoGenerator.newBuilder(10, 2).withMetaData(false).build().toApplications();
    XStream xstream = JsonXStream.getInstance();
    String jsonDocument = xstream.toXML(applications);
    Applications decodedApplications = (Applications) xstream.fromXML(jsonDocument);
    assertThat(EurekaEntityComparators.equal(decodedApplications, applications), is(true));
}
Also used : Applications(com.netflix.discovery.shared.Applications) XStream(com.thoughtworks.xstream.XStream) Test(org.junit.Test)

Aggregations

Applications (com.netflix.discovery.shared.Applications)120 Test (org.junit.Test)68 Application (com.netflix.discovery.shared.Application)41 InstanceInfo (com.netflix.appinfo.InstanceInfo)29 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)13 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)13 EurekaEntityFunctions.copyApplications (com.netflix.discovery.util.EurekaEntityFunctions.copyApplications)10 InstanceInfoGenerator (com.netflix.discovery.util.InstanceInfoGenerator)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)6 XStream (com.thoughtworks.xstream.XStream)6 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)5 InputStream (java.io.InputStream)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 Matchers.anyString (org.mockito.Matchers.anyString)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4