本文整理汇总了Java中com.netflix.hystrix.HystrixObservableCommand类的典型用法代码示例。如果您正苦于以下问题:Java HystrixObservableCommand类的具体用法?Java HystrixObservableCommand怎么用?Java HystrixObservableCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HystrixObservableCommand类属于com.netflix.hystrix包,在下文中一共展示了HystrixObservableCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConstructProvider
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Test
public void testConstructProvider() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
.andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
.andCommandPropertiesDefaults(setter));
Observable<Response> response = bizkeeperCommand.construct();
Assert.assertNotNull(response);
}
示例2: testGetCacheKeyWithContextInitializedProvider
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Test
public void testGetCacheKeyWithContextInitializedProvider() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
.andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
.andCommandPropertiesDefaults(setter));
HystrixRequestContext.initializeContext();
String cacheKey = bizkeeperCommand.getCacheKey();
Assert.assertNotNull(cacheKey);
}
示例3: testResumeWithFallbackConsumer
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Test
public void testResumeWithFallbackConsumer() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
.andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
.andCommandPropertiesDefaults(setter));
Observable<Response> observe = bizkeeperCommand.resumeWithFallback();
Assert.assertNotNull(observe);
}
示例4: testConstructConsumer
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Test
public void testConstructConsumer() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
.andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
.andCommandPropertiesDefaults(setter));
Observable<Response> response = bizkeeperCommand.construct();
Assert.assertNotNull(response);
}
示例5: testGetCacheKeyWithContextInitializedConsumer
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Test
public void testGetCacheKeyWithContextInitializedConsumer() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
.andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
.andCommandPropertiesDefaults(setter));
HystrixRequestContext.initializeContext();
String cacheKey = bizkeeperCommand.getCacheKey();
Assert.assertNotNull(cacheKey);
}
示例6: HttpResourceObservableCommand
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
public HttpResourceObservableCommand(HttpClient<ByteBuf, ByteBuf> httpClient,
HttpClientRequest<ByteBuf> httpRequest, String hystrixCacheKey,
Map<String, Object> requestProperties,
FallbackHandler<T> fallbackHandler,
ResponseValidator<HttpClientResponse<ByteBuf>> validator,
Class<? extends T> classType,
HystrixObservableCommand.Setter setter) {
super(setter);
this.httpClient = httpClient;
this.fallbackHandler = fallbackHandler;
this.validator = validator;
this.httpRequest = httpRequest;
this.hystrixCacheKey = hystrixCacheKey;
this.classType = classType;
this.requestProperties = requestProperties;
}
示例7: createBizkeeperCommand
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Override
protected BizkeeperCommand createBizkeeperCommand(Invocation invocation) {
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(false)
.withRequestLogEnabled(false);
setCommonProperties(invocation, setter);
BizkeeperCommand command = new ProviderBizkeeperCommand(groupname, invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey(groupname, invocation))
.andCommandKey(CommandKey.toHystrixCommandKey(groupname, invocation))
.andCommandPropertiesDefaults(setter));
return command;
}
示例8: createBizkeeperCommand
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Override
protected BizkeeperCommand createBizkeeperCommand(Invocation invocation) {
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false);
setCommonProperties(invocation, setter);
BizkeeperCommand command = new ConsumerBizkeeperCommand(groupname, invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey(groupname, invocation))
.andCommandKey(CommandKey.toHystrixCommandKey(groupname, invocation))
.andCommandPropertiesDefaults(setter));
return command;
}
示例9: createBizkeeperCommand
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Override
protected BizkeeperCommand createBizkeeperCommand(Invocation invocation) {
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
.andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
.andCommandPropertiesDefaults(setter));
return bizkeeperCommand;
}
示例10: testGetCacheKeyProvider
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Test
public void testGetCacheKeyProvider() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
.andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
.andCommandPropertiesDefaults(setter));
String str = bizkeeperCommand.getCacheKey();
Assert.assertNull(str);
Response resp = Mockito.mock(Response.class);
Mockito.when(resp.isFailed()).thenReturn(false);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.isFailed()).thenReturn(true);
InvocationException excp = Mockito.mock(InvocationException.class);
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(400);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(590);
Assert.assertEquals(true, bizkeeperCommand.isFailedResponse(resp));
}
示例11: testResumeWithFallbackProvider
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Test
public void testResumeWithFallbackProvider() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
.andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
.andCommandPropertiesDefaults(setter));
Observable<Response> observe = bizkeeperCommand.resumeWithFallback();
Assert.assertNotNull(observe);
}
示例12: testGetCacheKeyConsumer
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
@Test
public void testGetCacheKeyConsumer() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation,
HystrixObservableCommand.Setter
.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
.andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
.andCommandPropertiesDefaults(setter));
String str = bizkeeperCommand.getCacheKey();
Assert.assertNull(str);
Response resp = Mockito.mock(Response.class);
Mockito.when(resp.isFailed()).thenReturn(false);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.isFailed()).thenReturn(true);
InvocationException excp = Mockito.mock(InvocationException.class);
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(400);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(490);
Assert.assertEquals(true, bizkeeperCommand.isFailedResponse(resp));
}
示例13: build
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
protected ExchangeCommand build(ClientRequest<?> request){
HystrixObservableCommand.Setter setter = HystrixObservableCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKeyName))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandName))
.andCommandPropertiesDefaults(commandProperties
.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
.withFallbackEnabled(false));
return new ExchangeCommand(hystrixWebClient.getDelegate(),request,setter);
}
示例14: getObservableFunction
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
public Function<HystrixObservableCommand<T>, Observable<T>> getObservableFunction() {
Function<HystrixObservableCommand<T>, Observable<T>> observableFunc;
if (this.toObservable != null) {
observableFunc = this.toObservable;
} else if (this.eager) {
observableFunc = cmd -> cmd.observe();
} else { // apply a default onBackpressureBuffer if not eager
observableFunc = cmd -> cmd.toObservable().onBackpressureBuffer();
}
return observableFunc;
}
示例15: observe
import com.netflix.hystrix.HystrixObservableCommand; //导入依赖的package包/类
public void observe() throws Exception {
final String name = "Pinpoint";
final String expectedMessage = HystrixTestHelper.sayHello(name);
HystrixObservableCommand<String> helloObservableCommand = SayHelloObservableCommand.create(commandGroup, name);
String actualMessage = helloObservableCommand.observe()
.toBlocking()
.single();
Assert.assertEquals(expectedMessage, actualMessage);
HystrixTestHelper.waitForSpanDataFlush();
}