Skip to content

Commit

Permalink
refactor: align api with other sdks (#125)
Browse files Browse the repository at this point in the history
align api with other sdks
  • Loading branch information
nickybondarenko authored May 21, 2024
1 parent 9bc883c commit f29035b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/spotify/confidence/Confidence.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ public Confidence withContext(Map<String, ConfidenceValue> context) {
}

@Override
public void send(String eventName) {
public void track(String eventName) {
try {
client().send(eventName, getContext(), Optional.empty());
client().emit(eventName, getContext(), Optional.empty());
} catch (IllegalStateException e) {
// swallow this exception
}
}

@Override
public void send(String eventName, ConfidenceValue.Struct message) {
public void track(String eventName, ConfidenceValue.Struct message) {
try {
client().send(eventName, getContext(), Optional.of(message));
client().emit(eventName, getContext(), Optional.of(message));
} catch (IllegalStateException e) {
// swallow this exception
}
Expand Down Expand Up @@ -130,9 +130,9 @@ private ClientDelegate(
}

@Override
public void send(
public void emit(
String name, ConfidenceValue.Struct context, Optional<ConfidenceValue.Struct> message) {
this.eventSenderEngine.send(name, context, message);
this.eventSenderEngine.emit(name, context, message);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/spotify/confidence/EventSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

@Beta
public interface EventSender extends Contextual {
public void send(String eventName, ConfidenceValue.Struct message);
public void track(String eventName, ConfidenceValue.Struct message);

public void send(String eventName);
public void track(String eventName);

@Override
EventSender withContext(ConfidenceValue.Struct context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import java.util.Optional;

interface EventSenderEngine extends Closeable {
void send(String name, ConfidenceValue.Struct context, Optional<ConfidenceValue.Struct> message);
void emit(String name, ConfidenceValue.Struct context, Optional<ConfidenceValue.Struct> message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class EventSenderEngineImpl implements EventSenderEngine {
}

@Override
public void send(
public void emit(
String name, ConfidenceValue.Struct context, Optional<ConfidenceValue.Struct> message) {
if (intakeClosed) {
log.warn("EventSenderEngine is closed, dropping event {}", name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testCloseChildShouldNotCloseParentEngine() throws IOException {
public void testCloseChildShouldNotThrowFromSend() throws IOException {
final Confidence child = root.withContext(Map.of("child-key", ConfidenceValue.of("child")));
child.close();
child.send("Test");
child.track("Test");
}

@Test
Expand All @@ -51,7 +51,7 @@ public void testCloseChildShouldNotAffectParent()
final Confidence child = root.withContext(Map.of("child-key", ConfidenceValue.of("child")));
child.close();
root.resolveFlags("test").get();
root.send("test", ConfidenceValue.of(Map.of("messageKey", ConfidenceValue.of("parent"))));
root.track("test", ConfidenceValue.of(Map.of("messageKey", ConfidenceValue.of("parent"))));
}

@Test
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/com/spotify/confidence/EventSenderEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public void testEngineRejectsEventsAfterClosed() throws IOException {
clock,
DEFAULT_MAX_FLUSH_INTERVAL,
DEFAULT_MAX_MEMORY_CONSUMPTION);
engine.send(
engine.emit(
"navigate",
ConfidenceValue.of(ImmutableMap.of("key", ConfidenceValue.of("size"))),
Optional.empty());
engine.close();
engine.send(
engine.emit(
"navigate",
ConfidenceValue.of(ImmutableMap.of("key", ConfidenceValue.of("size"))),
Optional.empty());
Expand All @@ -59,7 +59,7 @@ public void testEngineUploads() throws IOException {
DEFAULT_MAX_MEMORY_CONSUMPTION);
int size = 0;
while (size++ < numEvents) {
engine.send(
engine.emit(
"navigate",
ConfidenceValue.of(ImmutableMap.of("key", ConfidenceValue.of("size"))),
Optional.empty());
Expand Down Expand Up @@ -93,7 +93,7 @@ public void testOverlappingKeysInPayload() throws InterruptedException {
DEFAULT_MAX_FLUSH_INTERVAL,
DEFAULT_MAX_MEMORY_CONSUMPTION);
// wait for the flush timeout to trigger the upload
engine.send(
engine.emit(
"my_event",
ConfidenceValue.of(
ImmutableMap.of(
Expand Down Expand Up @@ -146,7 +146,7 @@ public void testEngineUploadsTriggeredByFlushTimeout() throws IOException, Inter
DEFAULT_MAX_MEMORY_CONSUMPTION);

// send only one event
engine.send(
engine.emit(
"navigate",
ConfidenceValue.of(ImmutableMap.of("key", ConfidenceValue.of("size"))),
Optional.empty());
Expand Down Expand Up @@ -176,7 +176,7 @@ public void testEngineUploadsWhenIntermittentErrorWillRetry() throws IOException
DEFAULT_MAX_FLUSH_INTERVAL,
DEFAULT_MAX_MEMORY_CONSUMPTION);
for (int i = 0; i < numEvents; i++) {
engine.send(
engine.emit(
"test",
ConfidenceValue.Struct.EMPTY,
Optional.of(ConfidenceValue.of(ImmutableMap.of("id", ConfidenceValue.of(i)))));
Expand Down Expand Up @@ -219,7 +219,7 @@ public void multiThreadTest() throws IOException {
eventTasks[i] =
CompletableFuture.runAsync(
() -> {
engine.send(
engine.emit(
"navigate",
ConfidenceValue.of(ImmutableMap.of("key", ConfidenceValue.of("size"))),
Optional.empty());
Expand Down Expand Up @@ -250,7 +250,7 @@ public void testUnsentEventsAreCancelledOnThreadInterrupted() throws Exception {
// set up the engine so that it cannot support more than 1 event in memory
final EventSenderEngineImpl engine =
new EventSenderEngineImpl(10, fakeUploader, clock, Duration.ofMillis(10), 1024);
engine.send("fake", ConfidenceValue.Struct.EMPTY, Optional.empty());
engine.emit("fake", ConfidenceValue.Struct.EMPTY, Optional.empty());
isUploadCalled.join();
Thread.currentThread().interrupt();
engine.close();
Expand All @@ -272,9 +272,9 @@ public void testEngineWillRejectEventsIfOverMemoryThreshold() throws IOException
10, fakeUploader, clock, DEFAULT_MAX_FLUSH_INTERVAL, expectedEvent.getSerializedSize());

// send two events
engine.send("navigate", ConfidenceValue.of(Map.of()), Optional.empty());
engine.emit("navigate", ConfidenceValue.of(Map.of()), Optional.empty());
assertThat(engine.getEstimatedMemoryConsumption()).isEqualTo(expectedEvent.getSerializedSize());
engine.send("navigate", ConfidenceValue.of(Map.of()), Optional.empty());
engine.emit("navigate", ConfidenceValue.of(Map.of()), Optional.empty());

engine.close();
// the first event should be uploaded but the second one should not because it was rejected and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void close() throws IOException {
}

@Override
public void send(
public void emit(
String name, ConfidenceValue.Struct context, Optional<ConfidenceValue.Struct> message) {
events.add(event(name, context, message).setEventTime(clock.getTimestamp()).build());
}
Expand Down

0 comments on commit f29035b

Please sign in to comment.