Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 3b5d0b1

Browse files
author
Dino Oliva
committed
Removes current thread-local operations from CensusContext
1 parent 4f53ef4 commit 3b5d0b1

File tree

10 files changed

+10
-344
lines changed

10 files changed

+10
-344
lines changed

BUILD

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,6 @@ java_test(
6868
],
6969
)
7070

71-
java_test(
72-
name = "CensusScopeTest",
73-
srcs = ["core/javatests/com/google/census/CensusScopeTest.java"],
74-
deps = [
75-
":census-core",
76-
":census-core_native",
77-
"@guava//jar",
78-
"@jsr305//jar",
79-
"@junit//jar",
80-
"@truth//jar",
81-
],
82-
)
83-
8471
java_test(
8572
name = "MetricMapTest",
8673
srcs = ["core/javatests/com/google/census/MetricMapTest.java"],

core/java/com/google/census/CensusContext.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@ public final CensusContext with(
4848

4949
/**
5050
* Serializes the {@link CensusContext} into the on-the-wire representation.
51-
*
52-
* <p>The inverse of {@link CensusContextFactory#deserialize(ByteBuffer)} and should be based on
53-
* the {@link CensusContext} protobuf representation.
51+
* The inverse of {@link CensusContextFactory#deserialize()} and should be based on the
52+
* {@link CensusContext} protobuf representation.
5453
*
5554
* @return serialized bytes.
5655
*/
5756
public abstract ByteBuffer serialize();
5857

59-
/** Sets the current thread-local {@link CensusContext}. */
60-
public abstract void setCurrent();
61-
6258
/** Builder for {@link CensusContext}. */
6359
public abstract static class Builder {
6460
/**

core/java/com/google/census/CensusContextFactory.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,16 @@
2121
*/
2222
public abstract class CensusContextFactory {
2323
/**
24-
* Creates a {@link CensusContext} from the given on-the-wire encoded representation.
25-
*
26-
* <p>Should be the inverse of {@link CensusContext#serialize()}. The serialized representation
27-
* should be based on the {@link CensusContext} protobuf representation.
24+
* Creates a {@link CensusContext} from the given on-the-wire encoded representation. Should be
25+
* the inverse of {@link CensusContext#serialize()}. The serialized representation should be
26+
* based on the {@link CensusContext} protobuf representation.
2827
*
2928
* @param buffer on-the-wire representation of a {@link CensusContext}
3029
* @return a {@link CensusContext} deserialized from {@code buffer}
3130
*/
3231
@Nullable
3332
public abstract CensusContext deserialize(ByteBuffer buffer);
3433

35-
/** Returns the current thread-local {@link CensusContext}. */
36-
public abstract CensusContext getCurrent();
37-
3834
/** Returns the default {@link CensusContext}. */
3935
public abstract CensusContext getDefault();
4036
}

core/java/com/google/census/CensusScope.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

core/javatests/com/google/census/CensusContextFactoryTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,4 @@ public void testDeserializeEmpty() {
3030
assertThat(Census.getCensusContextFactory().deserialize(ByteBuffer.wrap(new byte[0])))
3131
.isEqualTo(Census.getCensusContextFactory().getDefault());
3232
}
33-
34-
@Test
35-
public void testGetCurrent() {
36-
assertThat(Census.getCensusContextFactory().getCurrent())
37-
.isEqualTo(Census.getCensusContextFactory().getDefault());
38-
}
3933
}

core/javatests/com/google/census/CensusContextTest.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
import static com.google.common.truth.Truth.assertThat;
1717

1818
import com.google.common.testing.EqualsTester;
19-
import java.util.concurrent.ExecutorService;
20-
import java.util.concurrent.Executors;
21-
import java.util.concurrent.Future;
2219
import org.junit.Test;
2320
import org.junit.runner.RunWith;
2421
import org.junit.runners.JUnit4;
@@ -116,35 +113,6 @@ public void testSerialize() {
116113
testSerialization(DEFAULT.with(K_EMPTY, V_EMPTY));
117114
}
118115

119-
@Test
120-
public void testSetCurrent() {
121-
assertThat(DEFAULT).isEqualTo(Census.getCensusContextFactory().getCurrent());
122-
123-
CensusContext context = DEFAULT.with(K1, V1);
124-
context.setCurrent();
125-
assertThat(context).isEqualTo(Census.getCensusContextFactory().getCurrent());
126-
127-
DEFAULT.setCurrent();
128-
assertThat(DEFAULT).isEqualTo(Census.getCensusContextFactory().getCurrent());
129-
}
130-
131-
@Test
132-
public void testMultipleThreadsWithContext() throws Exception {
133-
CensusContext currentContext = Census.getCensusContextFactory().getCurrent();
134-
CensusContext c1 = Census.getCensusContextFactory().getDefault().with(K1, V1);
135-
CensusContext c2 = Census.getCensusContextFactory().getDefault().with(K2, V2);
136-
ExecutorService executor = Executors.newFixedThreadPool(1);
137-
// Attach c1 to the executor thread.
138-
Future<?> future =
139-
executor.submit(withContext(Census.getCensusContextFactory().getDefault(), c1));
140-
future.get();
141-
// Verify that the context for the current thread was not updated.
142-
assertThat(Census.getCensusContextFactory().getCurrent()).isEqualTo(currentContext);
143-
// Attach c2 to the executor thread.
144-
future = executor.submit(withContext(c1, c2));
145-
future.get();
146-
}
147-
148116
// Tests for Object overrides.
149117

150118
@Test
@@ -173,15 +141,4 @@ private static void testSerialization(CensusContext expected) {
173141
CensusContext actual = Census.getCensusContextFactory().deserialize(expected.serialize());
174142
assertThat(actual).isEqualTo(expected);
175143
}
176-
177-
private static final Runnable withContext(final CensusContext prev, final CensusContext next) {
178-
return new Runnable() {
179-
@Override
180-
public void run() {
181-
assertThat(Census.getCensusContextFactory().getCurrent()).isEqualTo(prev);
182-
next.setCurrent();
183-
assertThat(Census.getCensusContextFactory().getCurrent()).isEqualTo(next);
184-
}
185-
};
186-
}
187144
}

core/javatests/com/google/census/CensusScopeTest.java

Lines changed: 0 additions & 145 deletions
This file was deleted.

core_native/java/com/google/census/CensusContextFactoryImpl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ public CensusContextImpl deserialize(ByteBuffer buffer) {
3232
return CensusSerializer.deserialize(buffer);
3333
}
3434

35-
@Override
36-
public CensusContext getCurrent() {
37-
return CensusCurrentContext.get();
38-
}
39-
4035
@Override
4136
public CensusContext getDefault() {
4237
return DEFAULT;

core_native/java/com/google/census/CensusContextImpl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ public ByteBuffer serialize() {
4444
return CensusSerializer.serialize(this);
4545
}
4646

47-
@Override
48-
public void setCurrent() {
49-
CensusCurrentContext.set(this);
50-
}
51-
5247
@Override
5348
public boolean equals(Object obj) {
5449
return (obj instanceof CensusContextImpl) && tags.equals(((CensusContextImpl) obj).tags);

0 commit comments

Comments
 (0)