Skip to content

Commit

Permalink
release 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mskonovalov committed Feb 21, 2017
2 parents 4ac45d5 + d66cab9 commit baa2e91
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ jdk:

script:
- ./gradlew --info check

- ./gradlew codeCoverageReport

after_success:
- bash <(curl -s https://codecov.io/bash)

notifications:
email: false
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2017 RingCentral, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@


[![][travis img]][travis]
[ ![Download][bintray img]][bintray]
[![Download][bintray img]][bintray]
[![codecov][codecov img]][codecov]
[![][license img]][license]


1. **ComposedHystrixMetricsPublisher**

Expand Down Expand Up @@ -35,4 +38,9 @@
[travis img]:https://travis-ci.org/ringcentral/hystrix-addons.svg?branch=master
[bintray]:https://bintray.com/ringcentral/maven/com.ringcentral.platform%3Ahystrix-addons/_latestVersion
[bintray img]:https://api.bintray.com/packages/ringcentral/maven/com.ringcentral.platform%3Ahystrix-addons/images/download.svg
[codecov]:https://codecov.io/gh/ringcentral/hystrix-addons
[codecov img]:https://codecov.io/gh/ringcentral/hystrix-addons/branch/develop/graph/badge.svg
[license]:LICENSE
[license img]:https://img.shields.io/badge/License-MIT-blue.svg


27 changes: 20 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ plugins {
id 'idea'
id 'maven'
id 'maven-publish'
id "com.jfrog.bintray" version "1.7.3"
id 'com.jfrog.bintray' version '1.7.3'
id 'jacoco'
}

group = 'com.ringcentral.platform'
version = '1.0.0'
version = '1.1.0'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down Expand Up @@ -48,8 +49,8 @@ publishing {
}

bintray {
user = hasProperty('user') ? property('user') : ''
key = hasProperty('key') ? property('key') : ''
user = project.hasProperty('user') ? property('user') : 'user'
key = project.hasProperty('key') ? property('key') : 'key'
publications = ['Mvn']
publish = true
override = true
Expand All @@ -65,11 +66,23 @@ bintray {
websiteUrl = 'https://github.com/ringcentral/hystrix-addons'
issueTrackerUrl = 'https://github.com/ringcentral/hystrix-addons/issues'
version {
name = '1.0.0'
desc = 'Hystrix-addons by Ringcentral, Inc. 1.0.0'
vcsTag = 'v1.0.0'
name = project.version
desc = "Hystrix-addons by Ringcentral, Inc. ${project.version}"
vcsTag = "v${project.version}"
}
}
}

task codeCoverageReport(type: JacocoReport) {

executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")

sourceSets sourceSets.main

reports {
xml.enabled true
xml.destination "${buildDir}/reports/jacoco/report.xml"
html.enabled false
csv.enabled false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Function;

/**
* Listener that notifies all the listeners about initialization of new command
Expand All @@ -24,15 +26,19 @@ public HystrixMetricsPublisherCommand getMetricsPublisherForCommand(
HystrixCommandMetrics metrics,
HystrixCircuitBreaker circuitBreaker,
HystrixCommandProperties properties) {
log.debug("Notify {} listeners for command {} and group {}", listeners.size(),
commandKey != null ? commandKey.name() : null,
commandGroupKey != null ? commandGroupKey.name(): null);
return () -> listeners.forEach(listener -> listener.initialize(metrics));
log.debug("Notify {} listeners for command {} and group {}", listeners.size(),
safe(commandKey, HystrixKey::name, "null"),
safe(commandGroupKey, HystrixKey::name, "null"));
return () -> listeners.forEach(listener -> listener.initialize(metrics));
}

public void addListener(HystrixMetricsInitializationListener listener) {
log.debug("Adding listener to HystrixMetricsInitializationNotifier");
listeners.add(listener);
log.debug("Adding listener to HystrixMetricsInitializationNotifier");
listeners.add(listener);
}

@SuppressWarnings("SameParameterValue")
private <T, U> U safe(T object, Function<T, U> f, U defaultValue) {
return Optional.ofNullable(object).map(f).orElse(defaultValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.ringcentral.platform.hystrix;

import com.netflix.hystrix.Hystrix;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.metric.HystrixCommandCompletion;
import com.netflix.hystrix.strategy.HystrixPlugins;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import org.junit.Before;
import org.junit.Test;
import rx.observers.TestSubscriber;

import static com.netflix.hystrix.HystrixEventType.FAILURE;
import static com.netflix.hystrix.HystrixEventType.SUCCESS;

public class AggregatedHystrixCommandCompletionStreamTest {

private final static HystrixCommandGroupKey GROUP_KEY = HystrixCommandGroupKey.Factory.asKey("Util");
private final static HystrixCommandKey COMMAND_1 = HystrixCommandKey.Factory.asKey("Command1");
private final static HystrixCommandKey COMMAND_2 = HystrixCommandKey.Factory.asKey("Command2");
private HystrixMetricsInitializationNotifier notifier = new HystrixMetricsInitializationNotifier();

@Before
public void setUp() {
Hystrix.reset();
HystrixPlugins.reset();
HystrixRequestContext.initializeContext();
HystrixPlugins.getInstance().registerMetricsPublisher(notifier);
}

@Test
public void testAggregatedStream() {
TestSubscriber<HystrixCommandCompletion> subscriber = new TestSubscriber<>();
new AggregatedHystrixCommandCompletionStream(notifier, t -> true).observe().subscribe(subscriber);
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_1, FAILURE, 10).execute();
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_2, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_2, FAILURE, 10).execute();
Command.from(GROUP_KEY, COMMAND_2, SUCCESS, 10).execute();

subscriber.assertValueCount(7);
subscriber.assertNoErrors();
subscriber.assertNoTerminalEvent();
}

@Test
public void testAggregatedStreamWithFilter() {
TestSubscriber<HystrixCommandCompletion> subscriber = new TestSubscriber<>();
new AggregatedHystrixCommandCompletionStream(notifier, c -> c.getCommandKey() == COMMAND_1).observe().subscribe(subscriber);
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_2, FAILURE, 10).execute();
Command.from(GROUP_KEY, COMMAND_1, FAILURE, 10).execute();
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 10).execute();

subscriber.assertValueCount(3);

Command.from(GROUP_KEY, COMMAND_2, SUCCESS, 10).execute();
Command.from(GROUP_KEY, COMMAND_2, SUCCESS, 10).execute();

subscriber.assertValueCount(3);
subscriber.assertNoErrors();
subscriber.assertNoTerminalEvent();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private void testSingleInitializePerKey(TestHystrixMetricsPublisher publisher) {
HystrixMetricsPublisherFactory.createOrRetrievePublisherForCommand(TestCommandKey.COMMAND_A, null, null, null, null);
HystrixMetricsPublisherFactory.createOrRetrievePublisherForCommand(TestCommandKey.COMMAND_B, null, null, null, null);
HystrixMetricsPublisherFactory.createOrRetrievePublisherForThreadPool(TestThreadPoolKey.THREAD_POOL_A, null, null);
HystrixMetricsPublisherFactory.createOrRetrievePublisherForCollapser(TestCollapserKey.COLLAPSER_A, null, null);
}));
}

Expand All @@ -56,12 +57,14 @@ private void testSingleInitializePerKey(TestHystrixMetricsPublisher publisher) {
// we should see 2 commands and 1 threadPool publisher created
assertEquals(2, publisher.commandCounter.get());
assertEquals(1, publisher.threadCounter.get());
assertEquals(1, publisher.threadCounter.get());
}

private static class TestHystrixMetricsPublisher extends HystrixMetricsPublisher {

AtomicInteger commandCounter = new AtomicInteger();
AtomicInteger threadCounter = new AtomicInteger();
AtomicInteger collapserCounter = new AtomicInteger();

@Override
public HystrixMetricsPublisherCommand getMetricsPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandOwner, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) {
Expand All @@ -73,6 +76,10 @@ public HystrixMetricsPublisherThreadPool getMetricsPublisherForThreadPool(Hystri
return threadCounter::incrementAndGet;
}

@Override
public HystrixMetricsPublisherCollapser getMetricsPublisherForCollapser(HystrixCollapserKey collapserKey, HystrixCollapserMetrics metrics, HystrixCollapserProperties properties) {
return collapserCounter::incrementAndGet;
}
}

private enum TestCommandKey implements HystrixCommandKey {
Expand All @@ -83,6 +90,9 @@ private enum TestThreadPoolKey implements HystrixThreadPoolKey {
THREAD_POOL_A
}

private enum TestCollapserKey implements HystrixCollapserKey {
COLLAPSER_A
}

private static class DummyPublisher extends HystrixMetricsPublisher {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ public class HystrixMetricsInitializationNotifierTest {
add(mock(HystrixMetricsInitializationListener.class));
add(mock(HystrixMetricsInitializationListener.class));
}};

private List<HystrixMetricsInitializationListener> listeners = new ArrayList<HystrixMetricsInitializationListener>(){{
addAll(mocks);
}};

private HystrixMetricsInitializationNotifier notifier = new HystrixMetricsInitializationNotifier(){{
listeners.forEach(this::addListener);
}};
Expand All @@ -60,13 +62,11 @@ public void checkNotifierIsCalledOnceForEveryCommand() {
HystrixPlugins.getInstance().registerMetricsPublisher(notifier);

for (int i = 0; i < 3; i++) {
HystrixCommand<Integer> cmd = Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 50);
cmd.observe();
Command.from(GROUP_KEY, COMMAND_1, SUCCESS, 50).observe();
}

for (int i = 0; i < 5; i++) {
HystrixCommand<Integer> cmd = Command.from(GROUP_KEY, COMMAND_2, FAILURE, 60);
cmd.observe();
Command.from(GROUP_KEY, COMMAND_2, FAILURE, 60).observe();
}

mocks.forEach(m -> {
Expand Down

0 comments on commit baa2e91

Please sign in to comment.