Search in sources :

Example 51 with HystrixCommandKey

use of com.netflix.hystrix.HystrixCommandKey in project Hystrix by Netflix.

the class HystrixMetricsPublisherFactoryTest method testMetricsPublisherReset.

@Test
public void testMetricsPublisherReset() {
    // precondition: HystrixMetricsPublisherFactory class is not loaded. Calling HystrixPlugins.reset() here should be good enough to run this with other tests.
    // set first custom publisher
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("key");
    HystrixMetricsPublisherCommand firstCommand = new HystrixMetricsPublisherCommandDefault(key, null, null, null, null);
    HystrixMetricsPublisher firstPublisher = new CustomPublisher(firstCommand);
    HystrixPlugins.getInstance().registerMetricsPublisher(firstPublisher);
    // ensure that first custom publisher is used
    HystrixMetricsPublisherCommand cmd = HystrixMetricsPublisherFactory.createOrRetrievePublisherForCommand(key, null, null, null, null);
    assertSame(firstCommand, cmd);
    // reset, then change to second custom publisher
    HystrixPlugins.reset();
    HystrixMetricsPublisherCommand secondCommand = new HystrixMetricsPublisherCommandDefault(key, null, null, null, null);
    HystrixMetricsPublisher secondPublisher = new CustomPublisher(secondCommand);
    HystrixPlugins.getInstance().registerMetricsPublisher(secondPublisher);
    // ensure that second custom publisher is used
    cmd = HystrixMetricsPublisherFactory.createOrRetrievePublisherForCommand(key, null, null, null, null);
    assertNotSame(firstCommand, cmd);
    assertSame(secondCommand, cmd);
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) Test(org.junit.Test)

Example 52 with HystrixCommandKey

use of com.netflix.hystrix.HystrixCommandKey in project java-chassis by ServiceComb.

the class TestCommandKey method testToHystrixCommandKey.

@Test
public void testToHystrixCommandKey() {
    Invocation invocation = Mockito.mock(Invocation.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
    Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
    Assert.assertNotNull(invocation);
    HystrixCommandKey hystrixCommandGroupKey = CommandKey.toHystrixCommandKey("groupname", invocation);
    Assert.assertNotNull(hystrixCommandGroupKey);
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) Invocation(io.servicecomb.core.Invocation) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 53 with HystrixCommandKey

use of com.netflix.hystrix.HystrixCommandKey in project Hystrix by Netflix.

the class HystrixUtilizationJsonStream method convertToJson.

protected static String convertToJson(HystrixUtilization utilization) throws IOException {
    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createGenerator(jsonString);
    json.writeStartObject();
    json.writeStringField("type", "HystrixUtilization");
    json.writeObjectFieldStart("commands");
    for (Map.Entry<HystrixCommandKey, HystrixCommandUtilization> entry : utilization.getCommandUtilizationMap().entrySet()) {
        final HystrixCommandKey key = entry.getKey();
        final HystrixCommandUtilization commandUtilization = entry.getValue();
        writeCommandUtilizationJson(json, key, commandUtilization);
    }
    json.writeEndObject();
    json.writeObjectFieldStart("threadpools");
    for (Map.Entry<HystrixThreadPoolKey, HystrixThreadPoolUtilization> entry : utilization.getThreadPoolUtilizationMap().entrySet()) {
        final HystrixThreadPoolKey threadPoolKey = entry.getKey();
        final HystrixThreadPoolUtilization threadPoolUtilization = entry.getValue();
        writeThreadPoolUtilizationJson(json, threadPoolKey, threadPoolUtilization);
    }
    json.writeEndObject();
    json.writeEndObject();
    json.close();
    return jsonString.getBuffer().toString();
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) StringWriter(java.io.StringWriter) HystrixThreadPoolUtilization(com.netflix.hystrix.metric.sample.HystrixThreadPoolUtilization) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) HystrixThreadPoolKey(com.netflix.hystrix.HystrixThreadPoolKey) Map(java.util.Map) HystrixCommandUtilization(com.netflix.hystrix.metric.sample.HystrixCommandUtilization)

Example 54 with HystrixCommandKey

use of com.netflix.hystrix.HystrixCommandKey in project Hystrix by Netflix.

the class HystrixServoMetricsPublisherCommandTest method testCumulativeCounters.

@Test
public void testCumulativeCounters() throws Exception {
    //execute 10 commands/sec (8 SUCCESS, 1 FAILURE, 1 TIMEOUT).
    //after 5 seconds, cumulative counters should have observed 50 commands (40 SUCCESS, 5 FAILURE, 5 TIMEOUT)
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("ServoCOMMAND-A");
    HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);
    HystrixCommandProperties properties = new HystrixPropertiesCommandDefault(key, propertiesSetter);
    HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(key, groupKey, properties);
    HystrixServoMetricsPublisherCommand servoPublisher = new HystrixServoMetricsPublisherCommand(key, groupKey, metrics, circuitBreaker, properties);
    servoPublisher.initialize();
    final int NUM_SECONDS = 5;
    for (int i = 0; i < NUM_SECONDS; i++) {
        new SuccessCommand(key).execute();
        new SuccessCommand(key).execute();
        new SuccessCommand(key).execute();
        Thread.sleep(10);
        new TimeoutCommand(key).execute();
        new SuccessCommand(key).execute();
        new FailureCommand(key).execute();
        new SuccessCommand(key).execute();
        new SuccessCommand(key).execute();
        new SuccessCommand(key).execute();
        Thread.sleep(10);
        new SuccessCommand(key).execute();
    }
    Thread.sleep(500);
    assertEquals(40L, servoPublisher.getCumulativeMonitor("success", HystrixEventType.SUCCESS).getValue());
    assertEquals(5L, servoPublisher.getCumulativeMonitor("timeout", HystrixEventType.TIMEOUT).getValue());
    assertEquals(5L, servoPublisher.getCumulativeMonitor("failure", HystrixEventType.FAILURE).getValue());
    assertEquals(10L, servoPublisher.getCumulativeMonitor("fallback_success", HystrixEventType.FALLBACK_SUCCESS).getValue());
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) HystrixCircuitBreaker(com.netflix.hystrix.HystrixCircuitBreaker) HystrixPropertiesCommandDefault(com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault) HystrixCommandMetrics(com.netflix.hystrix.HystrixCommandMetrics) Test(org.junit.Test)

Example 55 with HystrixCommandKey

use of com.netflix.hystrix.HystrixCommandKey in project Hystrix by Netflix.

the class HystrixServoMetricsPublisherCommandTest method testRollingLatencies.

@Test
public void testRollingLatencies() throws Exception {
    //execute 10 commands, then sleep for 2000ms to let these age out
    //execute 10 commands again, these should show up in rolling count
    HystrixCommandKey key = HystrixCommandKey.Factory.asKey("ServoCOMMAND-C");
    HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);
    HystrixCommandProperties properties = new HystrixPropertiesCommandDefault(key, propertiesSetter);
    HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(key, groupKey, properties);
    HystrixServoMetricsPublisherCommand servoPublisher = new HystrixServoMetricsPublisherCommand(key, groupKey, metrics, circuitBreaker, properties);
    servoPublisher.initialize();
    new SuccessCommand(key, 5).execute();
    new SuccessCommand(key, 5).execute();
    new SuccessCommand(key, 5).execute();
    new TimeoutCommand(key).execute();
    new SuccessCommand(key, 5).execute();
    new FailureCommand(key, 5).execute();
    new SuccessCommand(key, 5).execute();
    new SuccessCommand(key, 5).execute();
    new SuccessCommand(key, 5).execute();
    new SuccessCommand(key, 5).execute();
    Thread.sleep(2000);
    List<Observable<Integer>> os = new ArrayList<Observable<Integer>>();
    TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>();
    os.add(new SuccessCommand(key, 10).observe());
    os.add(new SuccessCommand(key, 20).observe());
    os.add(new SuccessCommand(key, 10).observe());
    os.add(new TimeoutCommand(key).observe());
    os.add(new SuccessCommand(key, 15).observe());
    os.add(new FailureCommand(key, 10).observe());
    os.add(new TimeoutCommand(key).observe());
    os.add(new TimeoutCommand(key).observe());
    os.add(new TimeoutCommand(key).observe());
    os.add(new TimeoutCommand(key).observe());
    Observable.merge(os).subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent(300, TimeUnit.MILLISECONDS);
    testSubscriber.assertCompleted();
    testSubscriber.assertNoErrors();
    //1 bucket roll
    Thread.sleep(100);
    int meanExecutionLatency = servoPublisher.getExecutionLatencyMeanMonitor("meanExecutionLatency").getValue().intValue();
    int p5ExecutionLatency = servoPublisher.getExecutionLatencyPercentileMonitor("p5ExecutionLatency", 5).getValue().intValue();
    int p25ExecutionLatency = servoPublisher.getExecutionLatencyPercentileMonitor("p25ExecutionLatency", 25).getValue().intValue();
    int p50ExecutionLatency = servoPublisher.getExecutionLatencyPercentileMonitor("p50ExecutionLatency", 50).getValue().intValue();
    int p75ExecutionLatency = servoPublisher.getExecutionLatencyPercentileMonitor("p75ExecutionLatency", 75).getValue().intValue();
    int p90ExecutionLatency = servoPublisher.getExecutionLatencyPercentileMonitor("p90ExecutionLatency", 90).getValue().intValue();
    int p99ExecutionLatency = servoPublisher.getExecutionLatencyPercentileMonitor("p99ExecutionLatency", 99).getValue().intValue();
    int p995ExecutionLatency = servoPublisher.getExecutionLatencyPercentileMonitor("p995ExecutionLatency", 99.5).getValue().intValue();
    System.out.println("Execution:           Mean : " + meanExecutionLatency + ", p5 : " + p5ExecutionLatency + ", p25 : " + p25ExecutionLatency + ", p50 : " + p50ExecutionLatency + ", p75 : " + p75ExecutionLatency + ", p90 : " + p90ExecutionLatency + ", p99 : " + p99ExecutionLatency + ", p99.5 : " + p995ExecutionLatency);
    int meanTotalLatency = servoPublisher.getTotalLatencyMeanMonitor("meanTotalLatency").getValue().intValue();
    int p5TotalLatency = servoPublisher.getTotalLatencyPercentileMonitor("p5TotalLatency", 5).getValue().intValue();
    int p25TotalLatency = servoPublisher.getTotalLatencyPercentileMonitor("p25TotalLatency", 25).getValue().intValue();
    int p50TotalLatency = servoPublisher.getTotalLatencyPercentileMonitor("p50TotalLatency", 50).getValue().intValue();
    int p75TotalLatency = servoPublisher.getTotalLatencyPercentileMonitor("p75TotalLatency", 75).getValue().intValue();
    int p90TotalLatency = servoPublisher.getTotalLatencyPercentileMonitor("p90TotalLatency", 90).getValue().intValue();
    int p99TotalLatency = servoPublisher.getTotalLatencyPercentileMonitor("p99TotalLatency", 99).getValue().intValue();
    int p995TotalLatency = servoPublisher.getTotalLatencyPercentileMonitor("p995TotalLatency", 99.5).getValue().intValue();
    System.out.println("Total:           Mean : " + meanTotalLatency + ", p5 : " + p5TotalLatency + ", p25 : " + p25TotalLatency + ", p50 : " + p50TotalLatency + ", p75 : " + p75TotalLatency + ", p90 : " + p90TotalLatency + ", p99 : " + p99TotalLatency + ", p99.5 : " + p995TotalLatency);
    assertTrue(meanExecutionLatency > 10);
    assertTrue(p5ExecutionLatency <= p25ExecutionLatency);
    assertTrue(p25ExecutionLatency <= p50ExecutionLatency);
    assertTrue(p50ExecutionLatency <= p75ExecutionLatency);
    assertTrue(p75ExecutionLatency <= p90ExecutionLatency);
    assertTrue(p90ExecutionLatency <= p99ExecutionLatency);
    assertTrue(p99ExecutionLatency <= p995ExecutionLatency);
    assertTrue(meanTotalLatency > 10);
    assertTrue(p5TotalLatency <= p25TotalLatency);
    assertTrue(p25TotalLatency <= p50TotalLatency);
    assertTrue(p50TotalLatency <= p75TotalLatency);
    assertTrue(p75TotalLatency <= p90TotalLatency);
    assertTrue(p90TotalLatency <= p99TotalLatency);
    assertTrue(p99TotalLatency <= p995TotalLatency);
    assertTrue(meanExecutionLatency <= meanTotalLatency);
    assertTrue(p5ExecutionLatency <= p5TotalLatency);
    assertTrue(p25ExecutionLatency <= p25TotalLatency);
    assertTrue(p50ExecutionLatency <= p50TotalLatency);
    assertTrue(p75ExecutionLatency <= p75TotalLatency);
    assertTrue(p90ExecutionLatency <= p90TotalLatency);
    assertTrue(p99ExecutionLatency <= p99TotalLatency);
    assertTrue(p995ExecutionLatency <= p995TotalLatency);
}
Also used : HystrixCommandKey(com.netflix.hystrix.HystrixCommandKey) ArrayList(java.util.ArrayList) HystrixCircuitBreaker(com.netflix.hystrix.HystrixCircuitBreaker) Observable(rx.Observable) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) TestSubscriber(rx.observers.TestSubscriber) HystrixPropertiesCommandDefault(com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault) HystrixCommandMetrics(com.netflix.hystrix.HystrixCommandMetrics) Test(org.junit.Test)

Aggregations

HystrixCommandKey (com.netflix.hystrix.HystrixCommandKey)113 Test (org.junit.Test)106 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)99 CountDownLatch (java.util.concurrent.CountDownLatch)99 HystrixThreadPoolKey (com.netflix.hystrix.HystrixThreadPoolKey)42 HystrixCommandGroupKey (com.netflix.hystrix.HystrixCommandGroupKey)38 ArrayList (java.util.ArrayList)25 CachedValuesHistogram (com.netflix.hystrix.metric.CachedValuesHistogram)9 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)8 HystrixContextRunnable (com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable)8 HystrixCommandMetrics (com.netflix.hystrix.HystrixCommandMetrics)7 HystrixCircuitBreaker (com.netflix.hystrix.HystrixCircuitBreaker)5 HystrixCommand (com.netflix.hystrix.HystrixCommand)4 Map (java.util.Map)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 HystrixPropertiesCommandDefault (com.netflix.hystrix.strategy.properties.HystrixPropertiesCommandDefault)3 StringWriter (java.io.StringWriter)3 HystrixCollapserKey (com.netflix.hystrix.HystrixCollapserKey)2 HystrixCollapserConfiguration (com.netflix.hystrix.config.HystrixCollapserConfiguration)2 HystrixCommandConfiguration (com.netflix.hystrix.config.HystrixCommandConfiguration)2