use of com.netflix.hystrix.HystrixCommand in project grakn by graknlabs.
the class BatchExecutorClientIT method whenSending100Queries_TheyAreSentInBatch.
@Ignore("This test interferes with other tests using the BEC (they probably use the same HystrixRequestLog)")
@Test
public void whenSending100Queries_TheyAreSentInBatch() {
List<Observable<QueryResponse>> all = new ArrayList<>();
// Increasing the max delay so eveyrthing goes in a single batch
try (BatchExecutorClient loader = loader(MAX_DELAY * 100)) {
int n = 100;
generate(this::query).limit(n).forEach(q -> all.add(loader.add(q, keyspace, true)));
int completed = allObservable(all).toBlocking().first().size();
assertEquals(n, completed);
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixCommand<?> command = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixCommand<?>[1])[0];
// assert the command is the one we're expecting
assertEquals("CommandQueries", command.getCommandKey().name());
// confirm that it was a COLLAPSED command execution
assertTrue(command.getExecutionEvents().contains(HystrixEventType.COLLAPSED));
// and that it was successful
assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
}
use of com.netflix.hystrix.HystrixCommand in project spring-cloud-sleuth by spring-cloud.
the class TraceCommandTests method should_pass_tracing_information_when_using_Hystrix_commands.
@Test
public void should_pass_tracing_information_when_using_Hystrix_commands() {
Tracer tracer = this.tracer;
TraceKeys traceKeys = new TraceKeys();
HystrixCommand.Setter setter = withGroupKey(asKey("group")).andCommandKey(HystrixCommandKey.Factory.asKey("command"));
// tag::hystrix_command[]
HystrixCommand<String> hystrixCommand = new HystrixCommand<String>(setter) {
@Override
protected String run() throws Exception {
return someLogic();
}
};
// end::hystrix_command[]
// tag::trace_hystrix_command[]
TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, traceKeys, setter) {
@Override
public String doRun() throws Exception {
return someLogic();
}
};
// end::trace_hystrix_command[]
String resultFromHystrixCommand = hystrixCommand.execute();
String resultFromTraceCommand = traceCommand.execute();
then(resultFromHystrixCommand).isEqualTo(resultFromTraceCommand);
}
use of com.netflix.hystrix.HystrixCommand in project data-prep by Talend.
the class CommandHelper method toPublisher.
/**
* Return a Publisher of type T out of the the hystrix command.
*
* @param clazz the wanted stream type.
* @param mapper the object mapper used to parse objects.
* @param command the hystrix command to deal with.
* @param <T> the type of objects to stream.
* @return a Publisher<T></T> out of the hystrix command response body.
*/
public static <T> Publisher<T> toPublisher(final Class<T> clazz, final ObjectMapper mapper, final HystrixCommand<InputStream> command) {
AtomicInteger count = new AtomicInteger(0);
return Flux.create(sink -> {
final Observable<InputStream> observable = command.toObservable();
observable.map(i -> {
try {
return mapper.readerFor(clazz).<T>readValues(i);
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}).doOnCompleted(//
() -> LOGGER.debug("Completed command '{}' (emits '{}') with '{}' records.", command.getClass().getName(), clazz.getName(), count.get())).toBlocking().forEach(s -> {
while (s.hasNext()) {
sink.next(s.next());
count.incrementAndGet();
}
sink.complete();
});
}, FluxSink.OverflowStrategy.BUFFER);
}
use of com.netflix.hystrix.HystrixCommand in project incubator-skywalking by apache.
the class HystrixCommandConstructorInterceptor method onConstruct.
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
String commandIdentify = "";
if (HystrixCommand.class.isAssignableFrom(objInst.getClass())) {
HystrixCommand hystrixCommand = (HystrixCommand) objInst;
commandIdentify = hystrixCommand.getCommandKey().name();
} else if (HystrixCollapser.class.isAssignableFrom(objInst.getClass())) {
HystrixCollapser hystrixCollapser = (HystrixCollapser) objInst;
commandIdentify = hystrixCollapser.getCollapserKey().name();
} else if (HystrixObservableCollapser.class.isAssignableFrom(objInst.getClass())) {
HystrixObservableCollapser hystrixObservableCollapser = (HystrixObservableCollapser) objInst;
commandIdentify = hystrixObservableCollapser.getCollapserKey().name();
} else if (HystrixObservableCommand.class.isAssignableFrom(objInst.getClass())) {
HystrixObservableCommand hystrixObservableCommand = (HystrixObservableCommand) objInst;
commandIdentify = hystrixObservableCommand.getCommandKey().name();
}
objInst.setSkyWalkingDynamicField(new EnhanceRequireObjectCache(OPERATION_NAME_PREFIX + commandIdentify));
}
use of com.netflix.hystrix.HystrixCommand in project ovirt-engine by oVirt.
the class HystrixBackendActionExecutor method execute.
@Override
public ActionReturnValue execute(final CommandBase<?> command) {
final HystrixCommand.Setter setter = HystrixSettings.setter(command.getActionType().name());
final HystrixCommand<ActionReturnValue> hystrixCommand = new HystrixCommand(setter) {
@Override
protected ActionReturnValue run() throws Exception {
final ActionReturnValue returnValue = command.executeAction();
if (returnValue.getSucceeded()) {
return returnValue;
}
// throw this so that hystrix can see that this command failed
throw new ActionFailedException(returnValue);
}
};
try {
return hystrixCommand.execute();
} catch (HystrixRuntimeException e) {
// only thrown for hystrix, so catch it and proceed normally
if (e.getCause() instanceof ActionFailedException) {
return ((ActionFailedException) e.getCause()).getReturnValue();
}
throw e;
}
}
Aggregations