-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV2-3003: Fix not listening for capabilities changes (#561)
* Fix bug for not updating of capabilities change * Formatting
- Loading branch information
Showing
8 changed files
with
69 additions
and
89 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
Common/src/main/java/com/tabnineCommon/capabilities/Capabilities.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.tabnineCommon.capabilities | ||
|
||
import com.tabnineCommon.binary.requests.capabilities.ExperimentSource | ||
|
||
data class Capabilities( | ||
val features: Set<Capability>, | ||
val experimentSource: ExperimentSource? | ||
) { | ||
fun isReady() = experimentSource == null || experimentSource.isRemoteBasedSource() | ||
|
||
fun isEnabled(capability: Capability) = features.contains(capability) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 28 additions & 19 deletions
47
Tabnine/src/test/java/com/tabnine/healthCheck/StatusBarWidgetTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,56 @@ | ||
package com.tabnine.healthCheck; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.tabnine.MockedBinaryCompletionTestCase; | ||
import com.tabnine.statusBar.TabnineStatusBarWidget; | ||
import com.tabnine.testUtils.HealthCheckTestUtils; | ||
import com.tabnine.testUtils.MockBinaryResponse; | ||
import com.tabnineCommon.binary.requests.capabilities.ExperimentSource; | ||
import com.tabnineCommon.binary.requests.config.CloudConnectionHealthStatus; | ||
import com.tabnineCommon.capabilities.CapabilitiesService; | ||
import com.tabnineCommon.capabilities.Capabilities; | ||
import com.tabnineCommon.capabilities.Capability; | ||
import com.tabnineCommon.capabilities.CapabilityNotifier; | ||
import com.tabnineCommon.general.ServiceLevel; | ||
import com.tabnineCommon.general.StaticConfig; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import org.junit.Test; | ||
|
||
public class StatusBarWidgetTests extends MockedBinaryCompletionTestCase { | ||
|
||
@Test | ||
public void should_get_connection_healthy_icon_when_connection_healthy() | ||
throws InterruptedException { | ||
public void should_get_connection_healthy_icon_when_connection_healthy() { | ||
TabnineStatusBarWidget widget = new TabnineStatusBarWidget(myFixture.getProject()); | ||
HealthCheckTestUtils.notifyStateForWidget( | ||
ServiceLevel.FREE, true, CloudConnectionHealthStatus.Ok); | ||
MockBinaryResponse.mockCapabilities(binaryProcessGatewayMock, "API", new ArrayList<>()); | ||
CapabilitiesService.getInstance().init(); | ||
|
||
while (!CapabilitiesService.getInstance().isReady()) { | ||
Thread.sleep(100); | ||
} | ||
CapabilityNotifier.Companion.publish(new Capabilities(new HashSet<>(), ExperimentSource.API)); | ||
|
||
assertEquals(StaticConfig.ICON_AND_NAME_STARTER, widget.getIcon()); | ||
} | ||
|
||
@Test | ||
public void should_get_connection_unhealthy_icon_when_connection_unhealthy() | ||
throws InterruptedException { | ||
public void should_get_connection_unhealthy_icon_when_connection_unhealthy() { | ||
TabnineStatusBarWidget widget = new TabnineStatusBarWidget(myFixture.getProject()); | ||
HealthCheckTestUtils.notifyStateForWidget( | ||
ServiceLevel.FREE, true, CloudConnectionHealthStatus.Failed); | ||
MockBinaryResponse.mockCapabilities(binaryProcessGatewayMock, "API", new ArrayList<>()); | ||
CapabilitiesService.getInstance().init(); | ||
|
||
while (!CapabilitiesService.getInstance().isReady()) { | ||
Thread.sleep(100); | ||
} | ||
CapabilityNotifier.Companion.publish(new Capabilities(new HashSet<>(), ExperimentSource.API)); | ||
|
||
assertEquals(StaticConfig.ICON_AND_NAME_CONNECTION_LOST_STARTER, widget.getIcon()); | ||
} | ||
|
||
@Test | ||
public void | ||
given_not_ready_source_then_ready_source_when_get_icon_should_return_no_suffix_then_suffix() { | ||
TabnineStatusBarWidget widget = new TabnineStatusBarWidget(myFixture.getProject()); | ||
HealthCheckTestUtils.notifyStateForWidget( | ||
ServiceLevel.FREE, true, CloudConnectionHealthStatus.Ok); | ||
CapabilityNotifier.Companion.publish( | ||
new Capabilities(new HashSet<>(), ExperimentSource.Unknown)); | ||
|
||
assertEquals(StaticConfig.ICON_AND_NAME, widget.getIcon()); | ||
|
||
CapabilityNotifier.Companion.publish( | ||
new Capabilities( | ||
Sets.immutableEnumSet(Capability.FORCE_REGISTRATION), ExperimentSource.API)); | ||
|
||
assertEquals(StaticConfig.ICON_AND_NAME_STARTER, widget.getIcon()); | ||
} | ||
} |
47 changes: 0 additions & 47 deletions
47
Tabnine/src/test/java/com/tabnine/testUtils/MockBinaryResponse.kt
This file was deleted.
Oops, something went wrong.