Add files via upload

This commit is contained in:
k0l0ssus 2018-08-07 00:16:23 -04:00 committed by GitHub
parent af4ddaeb34
commit ac9ef8d6d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 22 deletions

View File

@ -2,6 +2,7 @@ package com.baeldung.samples.jerseyrx;
import io.reactivex.Flowable;
import io.reactivex.disposables.Disposable;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
@ -31,6 +32,7 @@ public class ClientOrchestration {
WebTarget userIdService = client.target("http://localhost:8080/serviceA/id");
WebTarget nameService = client.target("http://localhost:8080/serviceA/{empId}/name");
WebTarget hashService = client.target("http://localhost:8080/serviceA/{comboIDandName}/hash");
LinkedList<Throwable> failures = new LinkedList<>();
Logger logger = Logger.getLogger("ClientOrchestrator");
@ -72,6 +74,7 @@ public class ClientOrchestration {
@Override
public void failed(Throwable throwable) {
completionTracker.countDown();
failures.add(throwable);
logger.log(Level.WARNING, "[InvocationCallback] An error has occurred in the hashing request step {0}", throwable.getMessage());
}
});
@ -80,6 +83,7 @@ public class ClientOrchestration {
@Override
public void failed(Throwable throwable) {
completionTracker.countDown();
failures.add(throwable);
logger.log(Level.WARNING, "[InvocationCallback] An error has occurred in the username request step {0}", throwable.getMessage());
}
});
@ -90,6 +94,7 @@ public class ClientOrchestration {
logger.warning("[InvocationCallback] Some requests didn't complete within the timeout");
}
} catch (InterruptedException ex) {
failures.add(ex);
Logger.getLogger(ClientOrchestration.class.getName()).log(Level.SEVERE, null, ex);
}
@ -97,6 +102,7 @@ public class ClientOrchestration {
@Override
public void failed(Throwable throwable) {
failures.add(throwable);
logger.warning("Couldn't get the list of IDs");
}
});
@ -108,7 +114,8 @@ public class ClientOrchestration {
.rx()
.get(new GenericType<EmployeeDTO>() {
})
.exceptionally((Throwable throwable) -> {
.exceptionally((throwable) -> {
failures.add(throwable);
logger.warning("[CompletionStage] An error has occurred");
return null;
});
@ -129,7 +136,8 @@ public class ClientOrchestration {
.get(String.class)
.toCompletableFuture()
.thenAcceptAsync(hashValue -> logger.log(Level.INFO, "[CompletionFuture] The hash output {0}", hashValue))
.exceptionally((Throwable throwable) -> {
.exceptionally((throwable) -> {
failures.add(throwable);
logger.log(Level.WARNING, "[CompletionStage] Hash computation failed for {0}", id);
return null;
});
@ -159,7 +167,10 @@ public class ClientOrchestration {
.rx(RxObservableInvoker.class)
.get(String.class)
.asObservable() //gotten the name for the given empId
.doOnError(throwable -> logger.log(Level.WARNING, " [Observable] An error has occurred in the username request step {0}", throwable.getMessage()))
.doOnError((throwable) -> {
failures.add(throwable);
logger.log(Level.WARNING, " [Observable] An error has occurred in the username request step {0}", throwable.getMessage());
})
.subscribe(userName -> hashService
.register(RxObservableInvokerProvider.class)
.resolveTemplate("comboIDandName", userName + id)
@ -167,13 +178,15 @@ public class ClientOrchestration {
.rx(RxObservableInvoker.class)
.get(String.class)
.asObservable() //gotten the hash value for empId+username
.doOnError(throwable -> logger.log(Level.WARNING, " [Observable]An error has occurred in the hashing request step {0}", throwable.getMessage()))
.doOnError((throwable) -> {
failures.add(throwable);
logger.log(Level.WARNING, " [Observable]An error has occurred in the hashing request step {0}", throwable.getMessage());
})
.subscribe(hashValue -> logger.log(Level.INFO, "[Observable] The hash output {0}", hashValue))));
});
}
public void flowableJavaOrchestrate() {
logger.info("Orchestrating with Flowable");
@ -191,13 +204,19 @@ public class ClientOrchestration {
.request()
.rx(RxFlowableInvoker.class)
.get(String.class) //gotten the name for the given empId
.doOnError(throwable -> logger.log(Level.WARNING, "[Flowable] An error has occurred in the username request step {0}", throwable.getMessage()))
.doOnError((throwable) -> {
failures.add(throwable);
logger.log(Level.WARNING, "[Flowable] An error has occurred in the username request step {0}", throwable.getMessage());
})
.subscribe(userName -> hashService.register(RxFlowableInvokerProvider.class)
.resolveTemplate("comboIDandName", userName + id)
.request()
.rx(RxFlowableInvoker.class)
.get(String.class) //gotten the hash value for empId+username
.doOnError(throwable -> logger.warning(" [Flowable] An error has occurred in the hashing request step " + throwable.getMessage()))
.doOnError((throwable) -> {
failures.add(throwable);
logger.warning(" [Flowable] An error has occurred in the hashing request step " + throwable.getMessage());
})
.subscribe(hashValue -> logger.log(Level.INFO, "[Flowable] The hash output {0}", hashValue))));
});

View File

@ -7,6 +7,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -16,52 +17,53 @@ import org.junit.Test;
* @author baeldung
*/
public class ClientOrchestrationTest {
ClientOrchestration orchestrator = new ClientOrchestration();
String jsonIdList = "{\"empIds\":[1,2,3,4,5,6]}";
String[] nameList = new String[]{"n/a", "Thor", "Hulk", "BlackWidow", "BlackPanther", "TheTick", "Hawkeye"};
String[] hashResultList = new String[]{"roht1", "kluh2", "WodiwKcalb3", "RehtnapKclab4", "kciteht5", "eyekwah6"};
WireMockServer wireMockServer = new WireMockServer();
@Before
public void setup() {
wireMockServer.start();
configureFor("localhost", 8080);
stubFor(get(urlEqualTo("/serviceA/id")).willReturn(aResponse().withBody(jsonIdList).withHeader("Content-Type", "application/json")));
stubFor(get(urlEqualTo("/serviceA/1/name")).willReturn(aResponse().withBody(nameList[1])));
stubFor(get(urlEqualTo("/serviceA/2/name")).willReturn(aResponse().withBody(nameList[2])));
stubFor(get(urlEqualTo("/serviceA/3/name")).willReturn(aResponse().withBody(nameList[3])));
stubFor(get(urlEqualTo("/serviceA/4/name")).willReturn(aResponse().withBody(nameList[4])));
stubFor(get(urlEqualTo("/serviceA/5/name")).willReturn(aResponse().withBody(nameList[5])));
stubFor(get(urlEqualTo("/serviceA/6/name")).willReturn(aResponse().withBody(nameList[6])));
stubFor(get(urlEqualTo("/serviceA/Thor1/hash")).willReturn(aResponse().withBody(hashResultList[0])));
stubFor(get(urlEqualTo("/serviceA/Hulk2/hash")).willReturn(aResponse().withBody(hashResultList[1])));
stubFor(get(urlEqualTo("/serviceA/BlackWidow3/hash")).willReturn(aResponse().withBody(hashResultList[2])));
stubFor(get(urlEqualTo("/serviceA/BlackPanther4/hash")).willReturn(aResponse().withBody(hashResultList[3])));
stubFor(get(urlEqualTo("/serviceA/TheTick5/hash")).willReturn(aResponse().withBody(hashResultList[4])));
stubFor(get(urlEqualTo("/serviceA/Hawkeye6/hash")).willReturn(aResponse().withBody(hashResultList[5])));
}
@Test
public void hits() {
orchestrator.callBackOrchestrate();
orchestrator.rxOrchestrate();
orchestrator.observableJavaOrchestrate();
orchestrator.flowableJavaOrchestrate();
Assert.assertTrue(orchestrator.failures.isEmpty());
}
@After
public void tearDown() {
}
}