Skip to content

Commit

Permalink
all: rename Storage test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-mastrangelo committed Nov 7, 2022
1 parent 6e5673b commit 808e971
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
Expand Up @@ -76,7 +76,7 @@ public void moduleElement_oldClass() throws Exception {
@Test
public void rewriteClass_task() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();
String expectedValue =
new StackTraceElement("loadername", "modulename", "moduleversion", "classname", "methodname", "filename", -1)
.toString();
Expand Down Expand Up @@ -109,7 +109,7 @@ public MethodVisitor visitMethod(
@Test
public void rewriteClass_closeable() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();
String expectedValue =
new StackTraceElement("loadername", "modulename", "moduleversion", "classname", "methodname", "filename", -1)
.toString();
Expand Down
28 changes: 14 additions & 14 deletions agent/src/test/java/io/perfmark/agent/PerfMarkTransformerTest.java
Expand Up @@ -60,7 +60,7 @@ public void deriveFileName_innerClass() {
public void transform_autoAnnotate() throws Exception {
// This test currently depends on the transformer treating this test class specially.
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(TransformerTestClasses.ClzAutoRecord.class);
Constructor<?> ctor = clz.getConstructor();
Expand All @@ -73,7 +73,7 @@ public void transform_autoAnnotate() throws Exception {
@Test
public void transform_record() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(TransformerTestClasses.SomeRecord.class);
Constructor<?> ctor = clz.getConstructor(int.class);
Expand All @@ -97,7 +97,7 @@ public void transform_record() throws Exception {
@Test
public void transform_lambda() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(TransformerTestClasses.ClzCtorLambda.class);
Constructor<?> ctor = clz.getConstructor();
Expand All @@ -121,7 +121,7 @@ public void transform_lambda() throws Exception {
@Test
public void transform_methodRef() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(TransformerTestClasses.ClzWithMethodRefs.class);
Constructor<?> ctor = clz.getConstructor();
Expand All @@ -135,7 +135,7 @@ public void transform_methodRef() throws Exception {
@Test
public void transform_interface() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz =
transformAndLoad(TransformerTestClasses.Bar.class, TransformerTestClasses.InterfaceWithDefaults.class);
Expand Down Expand Up @@ -178,7 +178,7 @@ public void transform_interface() throws Exception {
@Test
public void transform_link() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(TransformerTestClasses.ClzWithLinks.class);
Constructor<?> ctor = clz.getConstructor();
Expand All @@ -205,7 +205,7 @@ public void transform_link() throws Exception {
@Test
public void transform_closeable() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(TransformerTestClasses.ClzWithCloseable.class);
Constructor<?> ctor = clz.getConstructor();
Expand All @@ -232,7 +232,7 @@ public void transform_wrongCloseable() throws Exception {
// If the wrong static type is used, the agent won't be able to instrument it. Add a test to document this
// behavior.
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(TransformerTestClasses.ClzWithWrongCloseable.class);
Constructor<?> ctor = clz.getConstructor();
Expand All @@ -255,7 +255,7 @@ public void transform_wrongCloseable_autoCloseable() throws Exception {
// If the wrong static type is used, the agent won't be able to instrument it. Add a test to document this
// behavior.
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<? extends Closeable> clz = transformAndLoad(TaskCloseable.class).asSubclass(Closeable.class);
Constructor<? extends Closeable> ctor = clz.getDeclaredConstructor();
Expand All @@ -271,7 +271,7 @@ public void transform_wrongCloseable_autoCloseable() throws Exception {
@Test
public void transform_ctor() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(TransformerTestClasses.ClzWithCtor.class);
Constructor<?> ctor = clz.getConstructor();
Expand Down Expand Up @@ -312,7 +312,7 @@ public void transform_ctor() throws Exception {
@Test
public void transform_init() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(TransformerTestClasses.ClzWithInit.class);
Constructor<?> ctor = clz.getDeclaredConstructor();
Expand Down Expand Up @@ -353,7 +353,7 @@ public void transform_init() throws Exception {
@Test
public void transform_clinit() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(TransformerTestClasses.ClzWithClinit.class);
Constructor<?> ctor = clz.getDeclaredConstructor();
Expand Down Expand Up @@ -394,7 +394,7 @@ public void transform_clinit() throws Exception {
@Test
public void transform_toplevel() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(ClzFooter.class);
Constructor<?> ctor = clz.getDeclaredConstructor();
Expand Down Expand Up @@ -435,7 +435,7 @@ public void transform_toplevel() throws Exception {
@Test
public void transform_anonymousClass() throws Exception {
PerfMark.setEnabled(true);
Storage.resetForTest();
Storage.clearLocalStorage();

Class<?> clz = transformAndLoad(new Runnable() {
// avoid IntelliJ thinking this should be a lambda.
Expand Down
2 changes: 1 addition & 1 deletion api/src/test/java/io/perfmark/CompatibilityTest.java
Expand Up @@ -103,7 +103,7 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
if (storageClz != null) {
storageClz.getMethod("resetForTest").invoke(null);
storageClz.getMethod("clearLocalStorage").invoke(null);
}
}

Expand Down
10 changes: 5 additions & 5 deletions api/src/test/java/io/perfmark/PerfMarkTest.java
Expand Up @@ -259,7 +259,7 @@ public void checkPermission(Permission perm) {

@Test
public void allMethodForward_taskName() {
Storage.resetForTest();
Storage.clearLocalStorage();
PerfMark.setEnabled(true);

long gen = getGen();
Expand Down Expand Up @@ -319,7 +319,7 @@ public void allMethodForward_taskName() {

@Test
public void attachTag_nullFunctionFailsSilently() {
Storage.resetForTest();
Storage.clearLocalStorage();
PerfMark.setEnabled(true);

PerfMark.attachTag("name", "extra2", null);
Expand All @@ -330,7 +330,7 @@ public void attachTag_nullFunctionFailsSilently() {

@Test
public void attachTag_functionFailureSucceeds() {
Storage.resetForTest();
Storage.clearLocalStorage();
PerfMark.setEnabled(true);

PerfMark.attachTag(
Expand All @@ -346,7 +346,7 @@ public void attachTag_functionFailureSucceeds() {

@Test
public void attachTag_functionFailureObjectFailureSucceeds() {
Storage.resetForTest();
Storage.clearLocalStorage();
PerfMark.setEnabled(true);
Object o =
new Object() {
Expand All @@ -369,7 +369,7 @@ public String toString() {

@Test
public void attachTag_doubleFunctionFailureSucceeds() {
Storage.resetForTest();
Storage.clearLocalStorage();
PerfMark.setEnabled(true);

PerfMark.attachTag(
Expand Down
9 changes: 9 additions & 0 deletions impl/src/main/java/io/perfmark/impl/LocalMarkHolder.java
Expand Up @@ -16,16 +16,25 @@

package io.perfmark.impl;

/**
* A local MarkHolder is a class that gets the "current" MarkHolder based on context. For example, a thread local
* MarkHolder could use this class to pull the local MarkHolder from the threadlocal variable. Other implementations
* are possible as well.
*/
public abstract class LocalMarkHolder {

/**
* Removes the local markholder storage.
*/
public abstract void clear();

/**
* Get's the current MarkHolder for mutation. Only called from a tracing thread.
*/
public abstract MarkHolder acquire();

/**
* Releases the MarkHolder from being written too. Usually called very shortly after {@link #acquire()}.
* This method is meant to be overridden and should not be called from subclasses.
*/
public void release(MarkHolder markHolder) {}
Expand Down
4 changes: 2 additions & 2 deletions impl/src/main/java/io/perfmark/impl/MostlyThreadLocal.java
Expand Up @@ -48,11 +48,11 @@ public MarkHolder get() {

private MarkHolder getAndSetSlow() {
assert super.get() == null;
Thread thread = Thread.currentThread();
CopyOnWriteArrayList<Storage.MarkHolderHandle> handles = getHandles(thread);
Storage.MarkHolderHandle markHolderHandle;
MarkHolder markHolder;
Storage.MarkHolderAndHandle markHolderAndHandle;
Thread thread = Thread.currentThread();
CopyOnWriteArrayList<Storage.MarkHolderHandle> handles = getHandles(thread);
if (handles == null) {
markHolderAndHandle = Storage.allocateMarkHolder();
markHolder = markHolderAndHandle.markHolder();
Expand Down
11 changes: 1 addition & 10 deletions impl/src/main/java/io/perfmark/impl/Storage.java
Expand Up @@ -277,17 +277,8 @@ public static void clearGlobalIndex() {
}
}

public static void resetForTest() {
clearLocalStorage();
}

static void clearSoftRefsForTest() {
clearGlobalIndex();
}

@Nullable
public static MarkList readForTest() {
// FIXME
List<MarkList> lists = read();
for (MarkList list : lists) {
// This is slightly wrong as the thread ID could be reused.
Expand Down Expand Up @@ -318,7 +309,7 @@ public static final class MarkHolderHandle {
/**
* Returns the MarkHolder. May return {@code null} if the Thread is gone. If {@code null} is returned,
* then {@code getThreadRef().get() == null}. If a non-{@code null} value is returned, the thread may be dead or
* alive. Additionally, since the {@link #threadRef} may be externally clear, it is not certain that the Thread
* alive. Additionally, since the {@link #threadRef} may be externally cleared, it is not certain that the Thread
* is dead.
*/
public MarkHolder markHolder() {
Expand Down
6 changes: 3 additions & 3 deletions impl/src/test/java/io/perfmark/impl/StorageTest.java
Expand Up @@ -45,13 +45,13 @@ public class StorageTest {

@Test
public void threadsCleanedUp() throws Exception {
Storage.resetForTest();
Storage.clearLocalStorage();
final CountDownLatch latch = new CountDownLatch(1);
new Thread(
new Runnable() {
@Override
public void run() {
Storage.resetForTest();
Storage.clearLocalStorage();
Storage.linkAnyway(4096, 1234);
latch.countDown();
}
Expand All @@ -68,7 +68,7 @@ public void run() {
List<MarkList> firstRead = Storage.read();
assertEquals(1, firstRead.size());
// simulate an OOM
Storage.clearSoftRefsForTest();
Storage.clearGlobalIndex();
List<MarkList> secondRead = Storage.read();
assertEquals(0, secondRead.size());
}
Expand Down
2 changes: 1 addition & 1 deletion java6/src/test/java/io/perfmark/java6/AutoLoadTest.java
Expand Up @@ -32,7 +32,7 @@
public class AutoLoadTest {
@Test
public void autoLoad() {
Storage.resetForTest();
Storage.clearLocalStorage();
PerfMark.setEnabled(true);
PerfMark.startTask("hi");
PerfMark.stopTask("hi");
Expand Down
2 changes: 1 addition & 1 deletion java9/src/test/java/io/perfmark/java9/AutoLoadTest.java
Expand Up @@ -34,7 +34,7 @@
public class AutoLoadTest {
@Test
public void autoLoad() throws Exception {
Storage.resetForTest();
Storage.clearLocalStorage();
PerfMark.setEnabled(true);
PerfMark.startTask("hi");
PerfMark.stopTask("hi");
Expand Down

0 comments on commit 808e971

Please sign in to comment.