Fix thread-unsafe emitter usage in SeekableStreamSupervisorStateTest. (#12658)

The TestEmitter is used from different threads without concurrency
control. This patch makes the emitter thread-safe.
This commit is contained in:
Gian Merlino 2022-06-22 22:29:16 -07:00 committed by GitHub
parent b6f8d7a1b3
commit 4d892483ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import org.apache.druid.data.input.impl.ByteEntity;
import org.apache.druid.data.input.impl.DimensionSchema;
import org.apache.druid.data.input.impl.DimensionsSpec;
@ -1371,17 +1372,22 @@ public class SeekableStreamSupervisorStateTest extends EasyMockSupport
private static class TestEmitter extends NoopServiceEmitter
{
@GuardedBy("events")
private final List<Event> events = new ArrayList<>();
@Override
public void emit(Event event)
{
synchronized (events) {
events.add(event);
}
}
public List<Event> getEvents()
{
return events;
synchronized (events) {
return ImmutableList.copyOf(events);
}
}
}
}