Skip to content

Commit 03ada2d

Browse files
committed
fix ut
1 parent 7c042ce commit 03ada2d

File tree

7 files changed

+54
-14
lines changed

7 files changed

+54
-14
lines changed

contrib/grpc-contrib/src/test/java/com/salesforce/grpc/contrib/FallbackResolverTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package com.salesforce.grpc.contrib;
99

10-
import io.grpc.Attributes;
1110
import io.grpc.NameResolver;
1211
import io.grpc.NameResolverProvider;
1312
import org.junit.Test;
@@ -18,6 +17,8 @@
1817

1918
@SuppressWarnings("ALL")
2019
public class FallbackResolverTest {
20+
21+
private final NameResolverFakes fakes = new NameResolverFakes();
2122
@Test
2223
public void firstShouldFind() throws Exception {
2324
NameResolver fakeResolver = new FakeResolver();
@@ -26,7 +27,7 @@ public void firstShouldFind() throws Exception {
2627

2728
NameResolver.Factory factory = FallbackResolver.startWith(canResolve).thenCheck(cannotResolve);
2829

29-
assertEquals(fakeResolver, factory.newNameResolver(new URI("aaa://foo"), Attributes.EMPTY));
30+
assertEquals(fakeResolver, factory.newNameResolver(new URI("aaa://foo"), fakes.fakeArgs));
3031
}
3132

3233
@Test
@@ -37,7 +38,7 @@ public void secondShouldFind() throws Exception {
3738

3839
NameResolver.Factory factory = FallbackResolver.startWith(cannotResolve).thenCheck(canResolve);
3940

40-
assertEquals(fakeResolver, factory.newNameResolver(new URI("bbb://foo"), Attributes.EMPTY));
41+
assertEquals(fakeResolver, factory.newNameResolver(new URI("bbb://foo"), fakes.fakeArgs));
4142
}
4243

4344
@Test
@@ -46,7 +47,7 @@ public void neitherShouldFind() throws Exception {
4647

4748
NameResolver.Factory factory = FallbackResolver.startWith(cannotResolve).thenCheck(cannotResolve);
4849

49-
assertNull(factory.newNameResolver(new URI("bbb://foo"), Attributes.EMPTY));
50+
assertNull(factory.newNameResolver(new URI("bbb://foo"), fakes.fakeArgs));
5051
}
5152

5253
@Test
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2019, Salesforce.com, Inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
package com.salesforce.grpc.contrib;
9+
10+
import io.grpc.NameResolver;
11+
import io.grpc.SynchronizationContext;
12+
import io.grpc.internal.GrpcUtil;
13+
14+
import java.util.Map;
15+
16+
public class NameResolverFakes {
17+
final SynchronizationContext fakeSyncContext = new SynchronizationContext(new Thread.UncaughtExceptionHandler() {
18+
@Override
19+
public void uncaughtException(Thread t, Throwable e) {
20+
e.printStackTrace();
21+
}
22+
});
23+
final NameResolver.ServiceConfigParser fakeParser =new NameResolver.ServiceConfigParser() {
24+
@Override
25+
public NameResolver.ConfigOrError parseServiceConfig(Map<String, ?> rawServiceConfig) {
26+
return NameResolver.ConfigOrError.fromConfig(new Object());
27+
}
28+
};
29+
30+
final NameResolver.Args fakeArgs = NameResolver.Args.newBuilder()
31+
.setDefaultPort(GrpcUtil.DEFAULT_PORT_PLAINTEXT)
32+
.setProxyDetector(GrpcUtil.DEFAULT_PROXY_DETECTOR)
33+
.setSynchronizationContext(fakeSyncContext)
34+
.setServiceConfigParser(fakeParser)
35+
.build();
36+
}

contrib/grpc-contrib/src/test/java/com/salesforce/grpc/contrib/StaticResolverProviderTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,31 @@
2020
import static org.junit.Assert.*;
2121

2222
public class StaticResolverProviderTest {
23+
24+
private final NameResolverFakes fakes = new NameResolverFakes();
25+
2326
private final InetSocketAddress staticAddress = new InetSocketAddress("localhost", 55555);
2427

2528
@Test
2629
public void ProviderShouldProvide() {
2730
NameResolverProvider provider = StaticResolver.provider(staticAddress);
28-
NameResolver resolver = provider.newNameResolver(URI.create("mesh://some.service"), Attributes.EMPTY);
31+
NameResolver resolver = provider.newNameResolver(URI.create("mesh://some.service"), fakes.fakeArgs);
2932

3033
assertThat(resolver).isNotNull();
3134
}
3235

3336
@Test
3437
public void ResolverShouldHaveCorrectAuthority() {
3538
NameResolverProvider provider = StaticResolver.provider(staticAddress);
36-
NameResolver resolver = provider.newNameResolver(URI.create("mesh://some.service"), Attributes.EMPTY);
39+
NameResolver resolver = provider.newNameResolver(URI.create("mesh://some.service"), fakes.fakeArgs);
3740

3841
assertThat(resolver.getServiceAuthority()).isEqualTo("some.service");
3942
}
4043

4144
@Test
4245
public void ResolverShouldResolve() {
4346
NameResolverProvider provider = StaticResolver.provider(staticAddress);
44-
NameResolver resolver = provider.newNameResolver(URI.create("mesh://some.service"), Attributes.EMPTY);
47+
NameResolver resolver = provider.newNameResolver(URI.create("mesh://some.service"), fakes.fakeArgs);
4548

4649
AtomicBoolean isResolved = new AtomicBoolean();
4750

contrib/grpc-contrib/src/test/java/com/salesforce/grpc/contrib/context/AmbientContextEnforcerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.salesforce.grpc.contrib.HelloResponse;
1313
import com.salesforce.grpc.contrib.Statuses;
1414
import io.grpc.*;
15+
import io.grpc.Status.Code;
1516
import io.grpc.stub.StreamObserver;
1617
import io.grpc.testing.GrpcServerRule;
1718
import org.assertj.core.api.Condition;
@@ -114,7 +115,7 @@ public void serverEnforcerFailsMissing() {
114115
.has(new Condition<Throwable>() {
115116
@Override
116117
public boolean matches(Throwable throwable) {
117-
return Statuses.hasStatusCode(throwable, Status.Code.FAILED_PRECONDITION);
118+
return Statuses.hasStatusCode(throwable, Code.FAILED_PRECONDITION);
118119
}
119120
});
120121
}
@@ -141,7 +142,7 @@ public void serverEnforcerFailsIncomplete() {
141142
.has(new Condition<Throwable>() {
142143
@Override
143144
public boolean matches(Throwable throwable) {
144-
return Statuses.hasStatusCode(throwable, Status.Code.FAILED_PRECONDITION);
145+
return Statuses.hasStatusCode(throwable, Code.FAILED_PRECONDITION);
145146
}
146147
});
147148
});

contrib/grpc-contrib/src/test/java/com/salesforce/grpc/contrib/context/AmbientContextTransferTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
import io.grpc.ServerInterceptors;
1818
import io.grpc.stub.StreamObserver;
1919
import io.grpc.testing.GrpcServerRule;
20-
import org.awaitility.Duration;
2120
import org.junit.Before;
2221
import org.junit.Rule;
2322
import org.junit.Test;
2423

24+
import java.time.Duration;
2525
import java.util.concurrent.Executors;
2626
import java.util.concurrent.atomic.AtomicReference;
2727

2828
import static org.assertj.core.api.Assertions.assertThat;
29-
import static org.assertj.core.api.Assertions.fail;
3029
import static org.awaitility.Awaitility.await;
3130

3231
public class AmbientContextTransferTest {
@@ -191,7 +190,7 @@ public void sayHello(HelloRequest request, StreamObserver<HelloResponse> respons
191190
response -> assertThat(AmbientContext.current().get(ctxKey)).isEqualTo(expectedCtxValue),
192191
Context.currentContextExecutor(Executors.newSingleThreadExecutor()));
193192

194-
await().atMost(Duration.ONE_SECOND).until(futureResponse::isDone);
193+
await().atMost(Duration.ofSeconds(1)).until(futureResponse::isDone);
195194
});
196195

197196
assertThat(ctxValue.get()).isEqualTo(expectedCtxValue);

contrib/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
<artifactId>maven-surefire-plugin</artifactId>
240240
<version>3.0.0-M7</version>
241241
<configuration>
242-
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
242+
<argLine>-Xmx1024m</argLine>
243243
</configuration>
244244
</plugin>
245245

jprotoc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
<artifactId>maven-surefire-plugin</artifactId>
196196
<version>3.0.0-M7</version>
197197
<configuration>
198-
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
198+
<argLine>-Xmx1024m</argLine>
199199
</configuration>
200200
</plugin>
201201

0 commit comments

Comments
 (0)