Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Commit dfe12ec

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents d0ddac0 + 275a0f8 commit dfe12ec

File tree

5 files changed

+138
-17
lines changed

5 files changed

+138
-17
lines changed

artifactory.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if (project.hasProperty('netifiArtifactoryUsername') && project.hasProperty('net
3131
}
3232

3333
defaults {
34-
publications('maven')
34+
publications('mavenJava')
3535
}
3636
}
3737
}

build.gradle

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1+
buildscript {
2+
repositories {
3+
maven {
4+
url "https://plugins.gradle.org/m2/"
5+
}
6+
}
7+
dependencies {
8+
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
9+
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.8.1"
10+
}
11+
}
12+
113
plugins {
214
id 'com.gradle.build-scan' version '1.16' // declare before any other plugin
315
id 'com.google.osdetector' version '1.4.0'
416
id 'com.github.sherter.google-java-format' version '0.7.1' apply false
517
id 'com.github.johnrengelman.shadow' version '2.0.1' apply false
618
id 'me.champeau.gradle.jmh' version '0.4.7' apply false
719
id 'io.morethan.jmhreport' version '0.6.2.1' apply false
8-
id 'com.jfrog.artifactory' version '4.7.3'
9-
id 'com.jfrog.bintray' version '1.8.4'
1020
id 'io.spring.dependency-management' version '1.0.6.RELEASE' apply false
1121
id 'com.google.protobuf' version '0.8.5' apply false
1222
}
1323

14-
apply from: 'artifactory.gradle'
15-
apply from: 'bintray.gradle'
16-
1724
buildScan { licenseAgreementUrl = 'https://gradle.com/terms-of-service'; licenseAgree = 'yes' }
1825

26+
apply from: "artifactory.gradle"
27+
apply from: "bintray.gradle"
28+
1929
subprojects {
2030
apply plugin: 'io.spring.dependency-management'
2131
apply plugin: 'com.jfrog.bintray'
@@ -24,7 +34,7 @@ subprojects {
2434
apply plugin: 'com.github.sherter.google-java-format'
2535
apply plugin: 'maven'
2636
apply plugin: 'maven-publish'
27-
37+
2838
ext['reactor-bom.version'] = 'Californium-SR1'
2939
ext['rsocket.version'] = '0.11.9'
3040
ext['rsocket-rpc.version'] = '0.2.4'
@@ -45,7 +55,6 @@ subprojects {
4555
ext['zipkin.sender.version'] = '2.7.6'
4656
ext['hdrhistogram.version'] = '2.1.10'
4757
ext['netty.version'] = '4.1.29.Final'
48-
ext['netty-tcnative.version'] = '2.0.18.Final'
4958
ext['typesafe-config.version'] = '1.3.3'
5059

5160
sourceCompatibility = 1.8
@@ -77,10 +86,6 @@ subprojects {
7786
entry 'protobuf-java-util'
7887
}
7988

80-
dependencySet( group: 'io.netty', version: ext['netty-tcnative.version']) {
81-
entry 'netty-tcnative'
82-
}
83-
8489
dependency "com.hubspot.jackson:jackson-datatype-protobuf:${ext['jackson-protobuf.version']}"
8590
dependency "com.fasterxml.jackson.core:jackson-databind:${ext['jackson.version']}"
8691
dependency "com.google.guava:guava:${ext['guava.version']}"
@@ -163,4 +168,35 @@ subprojects {
163168
testCompile 'io.rsocket:rsocket-transport-local'
164169
testCompile 'org.mockito:mockito-core'
165170
}
171+
172+
// Build Source Jars
173+
def sourcesJarMap = [name: 'sourcesJar', type: Jar, dependsOn: classes]
174+
project.tasks.create(sourcesJarMap, {
175+
classifier = 'sources'
176+
from sourceSets.main.allSource
177+
version = "${project.version}"
178+
})
179+
180+
// Build Javadoc Jars
181+
def javadocJarMap = [name: 'javadocJar', type: Jar, dependsOn: javadoc]
182+
project.tasks.create(javadocJarMap, {
183+
classifier = 'javadoc'
184+
from javadoc.destinationDir
185+
version = "${project.version}"
186+
})
187+
188+
artifacts {
189+
archives sourcesJar
190+
archives javadocJar
191+
}
192+
193+
publishing {
194+
publications {
195+
mavenJava(MavenPublication) {
196+
from components.java
197+
artifact sourcesJar
198+
artifact javadocJar
199+
}
200+
}
201+
}
166202
}

proteus-client/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies {
1010
compile 'com.typesafe:config'
1111
compile 'com.google.guava:guava'
1212
compile 'io.rsocket.rpc:rsocket-rpc-core'
13-
compile 'io.netty:netty-tcnative::linux-x86_64'
13+
compile "io.netty:netty-tcnative:2.0.18.Final:linux-x86_64"
1414

1515
testProtobuf 'io.rsocket.rpc:rsocket-rpc-protobuf-idl'
1616
testCompile project(':proteus-tracing-openzipkin')

proteus-client/src/main/java/io/netifi/proteus/DefaultProteusBrokerService.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.netty.buffer.ByteBuf;
1717
import io.netty.buffer.ByteBufAllocator;
1818
import io.netty.buffer.Unpooled;
19+
import io.netty.util.ReferenceCountUtil;
1920
import io.opentracing.Tracer;
2021
import io.rsocket.Payload;
2122
import io.rsocket.RSocket;
@@ -24,6 +25,7 @@
2425
import io.rsocket.rpc.stats.Quantile;
2526
import io.rsocket.transport.ClientTransport;
2627
import io.rsocket.util.ByteBufPayload;
28+
import io.rsocket.util.DefaultPayload;
2729
import java.net.InetSocketAddress;
2830
import java.net.SocketAddress;
2931
import java.time.Duration;
@@ -264,10 +266,25 @@ WeightedReconnectingRSocket createWeightedReconnectingRSocket() {
264266
}
265267

266268
Payload getSetupPayload(String computedFromDestination) {
267-
ByteBuf metadata =
268-
DestinationSetupFlyweight.encode(
269-
ByteBufAllocator.DEFAULT, computedFromDestination, group, accessKey, accessToken);
270-
return ByteBufPayload.create(Unpooled.EMPTY_BUFFER, metadata);
269+
return getSetupPayload(
270+
ByteBufAllocator.DEFAULT, computedFromDestination, group, accessKey, accessToken);
271+
}
272+
273+
static Payload getSetupPayload(
274+
ByteBufAllocator alloc,
275+
String computedFromDestination,
276+
String group,
277+
long accessKey,
278+
ByteBuf accessToken) {
279+
ByteBuf metadata = null;
280+
try {
281+
metadata =
282+
DestinationSetupFlyweight.encode(
283+
alloc, computedFromDestination, group, accessKey, accessToken);
284+
return DefaultPayload.create(Unpooled.EMPTY_BUFFER, metadata);
285+
} finally {
286+
ReferenceCountUtil.safeRelease(metadata);
287+
}
271288
}
272289

273290
private ProteusSocket unwrappedDestination(String destination, String group) {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.netifi.proteus;
2+
3+
import io.netifi.proteus.frames.DestinationSetupFlyweight;
4+
import io.netty.buffer.*;
5+
import io.rsocket.Payload;
6+
import java.nio.charset.Charset;
7+
import java.util.Collection;
8+
import java.util.function.Function;
9+
import org.junit.*;
10+
11+
public class ProteusBrokerServiceTest {
12+
13+
@Test
14+
public void setupPayloadLeakTest() {
15+
ByteBuf token = Unpooled.wrappedBuffer("token".getBytes(Charset.defaultCharset()));
16+
PooledByteBufAllocator alloc = nonCachingAllocator();
17+
18+
for (int i = 0; i < 100000; i++) {
19+
Payload payload =
20+
DefaultProteusBrokerService.getSetupPayload(alloc, "foo", "bar", 123L, token);
21+
}
22+
Assert.assertEquals(0, directBuffersCount(alloc));
23+
Assert.assertEquals(0, heapBuffersCount(alloc));
24+
}
25+
26+
@Test
27+
public void setupDecodeTest() {
28+
String expectedToken = "token";
29+
String expectedDest = "foo";
30+
String expectedGroup = "bar";
31+
long expectedKey = 123L;
32+
33+
ByteBuf token = Unpooled.wrappedBuffer(expectedToken.getBytes(Charset.defaultCharset()));
34+
35+
Payload payload =
36+
DefaultProteusBrokerService.getSetupPayload(
37+
ByteBufAllocator.DEFAULT, expectedDest, expectedGroup, expectedKey, token);
38+
ByteBuf metadata = payload.sliceMetadata();
39+
String actualDest = DestinationSetupFlyweight.destination(metadata);
40+
String actualGroup = DestinationSetupFlyweight.group(metadata);
41+
long actualAccessKey = DestinationSetupFlyweight.accessKey(metadata);
42+
String actualAccessToken =
43+
DestinationSetupFlyweight.accessToken(metadata).toString(Charset.defaultCharset());
44+
45+
Assert.assertEquals(expectedToken, actualAccessToken);
46+
Assert.assertEquals(expectedDest, actualDest);
47+
Assert.assertEquals(expectedGroup, actualGroup);
48+
Assert.assertEquals(expectedKey, actualAccessKey);
49+
}
50+
51+
private static PooledByteBufAllocator nonCachingAllocator() {
52+
return new PooledByteBufAllocator(true, 1, 1, 8192, 11, 0, 0, 0);
53+
}
54+
55+
private static long directBuffersCount(PooledByteBufAllocator alloc) {
56+
return count(alloc, PooledByteBufAllocator::directArenas);
57+
}
58+
59+
private static long heapBuffersCount(PooledByteBufAllocator alloc) {
60+
return count(alloc, PooledByteBufAllocator::heapArenas);
61+
}
62+
63+
private static long count(
64+
PooledByteBufAllocator alloc,
65+
Function<PooledByteBufAllocator, Collection<PoolArenaMetric>> f) {
66+
return f.apply(alloc).stream().mapToLong(PoolArenaMetric::numActiveAllocations).sum();
67+
}
68+
}

0 commit comments

Comments
 (0)