Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Minor QoL clean up #175

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea/
/.vscode/

# Ignore Gradle project-specific cache directory
.gradle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.pyroscope.javaagent.impl;

import io.pyroscope.http.Format;
import io.pyroscope.javaagent.EventType;
import io.pyroscope.javaagent.Snapshot;
import io.pyroscope.javaagent.api.Exporter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public Ref(T val, Long id) {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Ref<T> valueRef = (Ref<T>) o;

Ref<?> valueRef = (Ref<?>) o;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this uses ? instead of T. I gather that ? is somewhat safer when casting generic classes.

return id.equals(valueRef.id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

import one.profiler.AsyncProfiler;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class PyroscopeAsyncProfiler {
static final String libraryPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void stressTest() throws InterruptedException {
}
e.shutdown();
e.awaitTermination(100, TimeUnit.SECONDS);
Snapshot res = Pyroscope.LabelsWrapper.dump();
Pyroscope.LabelsWrapper.dump();
assertEquals(0, ScopedContext.context.get().id);
assertEquals(0, RefCounted.strings.valueToRef.size());
assertEquals(0, RefCounted.contexts.valueToRef.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.pyroscope.labels;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class RefTest {
@Test
void testCreateRef() {
Ref<String> ref = new Ref<>("test", 1L);
assertEquals("test", ref.val);
assertEquals(1L, ref.id);
assertEquals(1L, ref.refCount.get());
}

@Test
@SuppressWarnings("unlikely-arg-type")
void testEquals() {
Ref<String> ref1 = new Ref<>("test", 1L);
assertTrue(ref1.equals(ref1));
assertFalse(ref1.equals(null));
assertFalse(ref1.equals(new Integer(3)));
assertTrue(ref1.equals(new Ref<Integer>(3, 1L))); // We don't compare the value types.
}

@Test
void testHashCode() {
Ref<String> ref1 = new Ref<>("test", 1L);
assertEquals(1, ref1.hashCode());
}
}
2 changes: 0 additions & 2 deletions demo/src/main/java/Fib.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down
Loading