Skip to content

Commit

Permalink
Remove implicit deduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
taldekar committed Jan 27, 2025
1 parent d2a4a11 commit 005595e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public void accept(final T event) {
}
};

return eventBus.ofType(eventType).distinct()
return eventBus.ofType(eventType)
.observeOn(Schedulers.computation())
.subscribe(consumer);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class DefaultAuthStateManager implements AuthStateManager {
private LoginParams loginParams; // used in login's getSsoToken params
private String issuerUrl; // used in AmazonQLspClientImpl.getConnectionMetadata()
private String ssoTokenId; // used in logout's invalidateSsoToken params
private AuthState previousAuthState = null;

public DefaultAuthStateManager(final PluginStore pluginStore) {
this.authPluginStore = new AuthPluginStore(pluginStore);
Expand Down Expand Up @@ -82,7 +83,6 @@ public void toExpired() {
toLoggedOut();
return;
}

updateState(AuthStateType.EXPIRED, loginType, loginParams, ssoTokenId);
}

Expand Down Expand Up @@ -119,7 +119,11 @@ private void updateState(final AuthStateType authStatusType, final LoginType log
* This notification is critical for ensuring all plugin components reflect the current
* authentication state.
*/
Activator.getEventBroker().post(getAuthState());
AuthState newAuthState = getAuthState();
if (previousAuthState == null || newAuthState.authStateType() != previousAuthState.authStateType()) {
Activator.getEventBroker().post(newAuthState);
}
previousAuthState = newAuthState;
}

private void syncAuthStateWithPluginStore() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import java.util.Objects;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -20,37 +18,7 @@

public final class EventBrokerTest {

private final class TestEvent {

private final String message;
private final int id;

TestEvent(final String message, final int id) {
this.message = message;
this.id = id;
}

public int getId() {
return id;
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
TestEvent other = (TestEvent) obj;
return this.id == other.getId();
}

@Override
public int hashCode() {
return Objects.hash(id);
}

private record TestEvent(String message, int id) {
}

private EventBroker eventBroker;
Expand All @@ -73,24 +41,6 @@ void testEventDelivery() {
subscription.dispose();
}

@Test
void testDistinctEventsOnly() {
TestEvent testEvent = new TestEvent("a message", 1);
TestEvent duplicateEvent = new TestEvent("another message", 1);
TestEvent uniqueEvent = new TestEvent("a message", 2);

EventObserver<TestEvent> mockObserver = mock(EventObserver.class);

Disposable subscription = eventBroker.subscribe(TestEvent.class, mockObserver);
eventBroker.post(testEvent);
eventBroker.post(duplicateEvent);
eventBroker.post(uniqueEvent);

verify(mockObserver, timeout(100).times(2)).onEvent(any(TestEvent.class));

subscription.dispose();
}

@Test
void testNullEventsIgnored() {
EventObserver<String> mockObserver = mock(EventObserver.class);
Expand Down

0 comments on commit 005595e

Please sign in to comment.