Search in sources :

Example 91 with Applications

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

the class XmlXStreamTest method testEncodingDecodingWithMetaData.

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

Example 92 with Applications

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

the class XmlXStreamTest method testEncodingDecodingWithoutMetaData.

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

Example 93 with Applications

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

the class EurekaJacksonCodecIntegrationTest method testDecodeTimeout.

/**
 * parse discovery response with an unreasonable timeout, so that the
 * parsing job is cancelled
 *
 * @throws Exception
 */
@Test
public void testDecodeTimeout() throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool(5);
    File localDiscovery = downloadRegistration(System.getProperty("discovery.url"));
    Callable<Applications> task = () -> {
        try (InputStream is = new FileInputStream(localDiscovery)) {
            return codec.readValue(Applications.class, is);
        }
    };
    final int cancelAllButNthTask = 3;
    for (int i = 0; i < 30; i++) {
        Future<Applications> appsFuture = executor.submit(task);
        if (i % cancelAllButNthTask < cancelAllButNthTask - 1) {
            Thread.sleep(UNREASONABLE_TIMEOUT_MS);
            System.out.println("cancelling..." + " i: " + i + " - " + (i % 3));
            appsFuture.cancel(true);
        }
        try {
            Applications apps = appsFuture.get();
            System.out.println("found some applications: " + apps.toString() + ":" + apps.getRegisteredApplications().size() + " i: " + i + " - " + (i % 3));
        } catch (Exception e) {
            System.out.println(e + " cause: " + " i: " + i + " - " + (i % 3));
        }
    }
}
Also used : Applications(com.netflix.discovery.shared.Applications) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 94 with Applications

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

the class EurekaJacksonCodecIntegrationTest method testRealDecode.

/**
 * parse discovery response in a long-running loop with a delay
 *
 * @throws Exception
 */
@Test
public void testRealDecode() throws Exception {
    Applications applications;
    // downloadRegistration(System.getProperty("discovery.url"));
    File localDiscovery = new File("/var/folders/6j/qy6n1npj11x5j2j_9ng2wzmw0000gp/T/discovery-data-6054758555577530004.json");
    long testStart = System.currentTimeMillis();
    for (int i = 0; i < 60; i++) {
        try (InputStream is = new FileInputStream(localDiscovery)) {
            long start = System.currentTimeMillis();
            applications = codec.readValue(Applications.class, is);
            System.out.println("found some applications: " + applications.getRegisteredApplications().size() + " et: " + (System.currentTimeMillis() - start));
        }
    }
    System.out.println("test time: " + " et: " + (System.currentTimeMillis() - testStart));
}
Also used : Applications(com.netflix.discovery.shared.Applications) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 95 with Applications

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

the class EurekaHttpClientCompatibilityTestSuite method testGetVipRequest.

@Test
public void testGetVipRequest() throws Exception {
    Applications vipApps = InstanceInfoGenerator.newBuilder(1, 2).build().toApplications();
    String vipAddress = vipApps.getRegisteredApplications().get(0).getInstances().get(0).getVIPAddress();
    when(requestHandler.getVip(vipAddress)).thenReturn(createResponse(vipApps));
    EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getVip(vipAddress);
    verifyResponseOkWithEntity(vipApps, httpResponse);
}
Also used : Applications(com.netflix.discovery.shared.Applications) 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