-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
AVRO-4069: Remove Reader String Cache from Generic Datum Reader #3194
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,6 @@ | |
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import org.apache.avro.Schema; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -33,27 +31,9 @@ public class TestGenericDatumReader { | |
|
||
private static final Random r = new Random(System.currentTimeMillis()); | ||
|
||
@Test | ||
void readerCache() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you delete the test ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is testing the thread-safe nature of the code. This code should not be considered thread-safe and therefore should be removed. |
||
final GenericDatumReader.ReaderCache cache = new GenericDatumReader.ReaderCache(this::findStringClass); | ||
List<Thread> threads = IntStream.rangeClosed(1, 200).mapToObj((int index) -> { | ||
final Schema schema = TestGenericDatumReader.this.build(index); | ||
final WithSchema s = new WithSchema(schema, cache); | ||
return (Runnable) () -> s.test(); | ||
}).map(Thread::new).collect(Collectors.toList()); | ||
threads.forEach(Thread::start); | ||
threads.forEach((Thread t) -> { | ||
try { | ||
t.join(); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
void newInstanceFromString() { | ||
final GenericDatumReader.ReaderCache cache = new GenericDatumReader.ReaderCache(this::findStringClass); | ||
final GenericDatumReader cache = new GenericDatumReader(); | ||
|
||
Object object = cache.newInstanceFromString(StringBuilder.class, "Hello"); | ||
assertEquals(StringBuilder.class, object.getClass()); | ||
|
@@ -62,21 +42,6 @@ void newInstanceFromString() { | |
|
||
} | ||
|
||
static class WithSchema { | ||
private final Schema schema; | ||
|
||
private final GenericDatumReader.ReaderCache cache; | ||
|
||
public WithSchema(Schema schema, GenericDatumReader.ReaderCache cache) { | ||
this.schema = schema; | ||
this.cache = cache; | ||
} | ||
|
||
public void test() { | ||
this.cache.getStringClass(schema); | ||
} | ||
} | ||
|
||
private List<Schema> list = new ArrayList<>(); | ||
|
||
private Schema build(int index) { | ||
|
Check notice
Code scanning / CodeQL
Missing catch of NumberFormatException Note