Skip to content

Commit 594c4dc

Browse files
committed
Unit test.
1 parent c1c952f commit 594c4dc

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

core/src/main/java/io/grpc/internal/CallExecutors.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,4 @@ static Executor safeguard(Executor executor) {
4343
}
4444
return new SerializingExecutor(executor);
4545
}
46-
47-
/**
48-
* Returns true if the executor is safeguarded (e.g. a {@link SerializingExecutor} or
49-
* {@link SerializeReentrantCallsDirectExecutor}).
50-
*/
51-
static boolean isSafeguarded(Executor executor) {
52-
return executor instanceof SerializingExecutor
53-
|| executor instanceof SerializeReentrantCallsDirectExecutor;
54-
}
5546
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2026 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.internal;
18+
19+
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
20+
import static org.junit.Assert.assertSame;
21+
import static org.junit.Assert.assertTrue;
22+
23+
import java.util.concurrent.Executor;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.junit.runners.JUnit4;
27+
28+
@RunWith(JUnit4.class)
29+
public class CallExecutorsTest {
30+
31+
@Test
32+
public void safeguard_alreadySerializing_returnsSameInstance() {
33+
Executor raw = command -> command.run();
34+
SerializingExecutor serializing = new SerializingExecutor(raw);
35+
assertSame(serializing, CallExecutors.safeguard(serializing));
36+
}
37+
38+
@Test
39+
public void safeguard_alreadySerializeReentrantCallsDirect_returnsSameInstance() {
40+
SerializeReentrantCallsDirectExecutor direct = new SerializeReentrantCallsDirectExecutor();
41+
assertSame(direct, CallExecutors.safeguard(direct));
42+
}
43+
44+
@Test
45+
public void safeguard_directExecutor_returnsSerializeReentrantCallsDirect() {
46+
Executor safeguarded = CallExecutors.safeguard(directExecutor());
47+
assertTrue(safeguarded instanceof SerializeReentrantCallsDirectExecutor);
48+
}
49+
50+
@Test
51+
public void safeguard_otherExecutor_returnsSerializing() {
52+
Executor raw = command -> command.run();
53+
Executor safeguarded = CallExecutors.safeguard(raw);
54+
assertTrue(safeguarded instanceof SerializingExecutor);
55+
}
56+
57+
@Test
58+
public void safeguard_idempotent() {
59+
Executor raw = command -> command.run();
60+
Executor first = CallExecutors.safeguard(raw);
61+
Executor second = CallExecutors.safeguard(first);
62+
assertSame(first, second);
63+
64+
Executor firstDirect = CallExecutors.safeguard(directExecutor());
65+
Executor secondDirect = CallExecutors.safeguard(firstDirect);
66+
assertSame(firstDirect, secondDirect);
67+
}
68+
}

0 commit comments

Comments
 (0)