@Test public void testPublishTelemetryFullQueue() { when(mMockTelemetryQueue.offer(mMockTelemetryEvent)).thenReturn(false); when(mMockTelemetryQueue.size()).thenReturn(1); assertThat(mTestIotCoreClient.publishTelemetry(mMockTelemetryEvent)).isFalse(); verify(mMockSemaphore, never()).release(); }
public boolean publishTelemetry(@NonNull TelemetryEvent event) { synchronized (mQueueLock) { int preOfferSize = mTelemetryQueue.size(); if (!mTelemetryQueue.offer(event) || mTelemetryQueue.size() == preOfferSize) { return false; } } mSemaphore.release(); return true; }
IotCoreClient { public boolean publishTelemetry(@NonNull TelemetryEvent event) { synchronized (mQueueLock) { int preOfferSize = mTelemetryQueue.size(); if (!mTelemetryQueue.offer(event) || mTelemetryQueue.size() == preOfferSize) { return false; } } mSemaphore.release(); return true; } }
IotCoreClient { public boolean publishTelemetry(@NonNull TelemetryEvent event) { synchronized (mQueueLock) { int preOfferSize = mTelemetryQueue.size(); if (!mTelemetryQueue.offer(event) || mTelemetryQueue.size() == preOfferSize) { return false; } } mSemaphore.release(); return true; } private  IotCoreClient(
            @NonNull ConnectionParams connectionParams,
            @NonNull KeyPair keyPair,
            @NonNull MqttClient mqttClient,
            @NonNull Queue<TelemetryEvent> telemetryQueue,
            @Nullable Executor connectionCallbackExecutor,
            @Nullable ConnectionCallback connectionCallback,
            @Nullable Executor onConfigurationExecutor,
            @Nullable OnConfigurationListener onConfigurationListener,
            @Nullable Executor onCommandExecutor,
            @Nullable OnCommandListener onCommandListener); @VisibleForTesting  IotCoreClient(
            @NonNull ConnectionParams configuration,
            @NonNull MqttClient mqttClient,
            @NonNull JwtGenerator jwtGenerator,
            @NonNull AtomicBoolean runBackgroundThread,
            @NonNull AtomicReference<byte[]> unsentDeviceState,
            @NonNull Queue<TelemetryEvent> telemetryQueue,
            @Nullable Executor connectionCallbackExecutor,
            @Nullable ConnectionCallback connectionCallback,
            @Nullable Executor onConfigurationExecutor,
            @Nullable OnConfigurationListener onConfigurationListener,
            @Nullable Executor onCommandExecutor,
            @Nullable OnCommandListener onCommandListener,
            @NonNull Semaphore semaphore,
            @NonNull BoundedExponentialBackoff backoff,
            @NonNull AtomicBoolean clientConnectionState); }
IotCoreClient { public boolean publishTelemetry(@NonNull TelemetryEvent event) { synchronized (mQueueLock) { int preOfferSize = mTelemetryQueue.size(); if (!mTelemetryQueue.offer(event) || mTelemetryQueue.size() == preOfferSize) { return false; } } mSemaphore.release(); return true; } private  IotCoreClient(
            @NonNull ConnectionParams connectionParams,
            @NonNull KeyPair keyPair,
            @NonNull MqttClient mqttClient,
            @NonNull Queue<TelemetryEvent> telemetryQueue,
            @Nullable Executor connectionCallbackExecutor,
            @Nullable ConnectionCallback connectionCallback,
            @Nullable Executor onConfigurationExecutor,
            @Nullable OnConfigurationListener onConfigurationListener,
            @Nullable Executor onCommandExecutor,
            @Nullable OnCommandListener onCommandListener); @VisibleForTesting  IotCoreClient(
            @NonNull ConnectionParams configuration,
            @NonNull MqttClient mqttClient,
            @NonNull JwtGenerator jwtGenerator,
            @NonNull AtomicBoolean runBackgroundThread,
            @NonNull AtomicReference<byte[]> unsentDeviceState,
            @NonNull Queue<TelemetryEvent> telemetryQueue,
            @Nullable Executor connectionCallbackExecutor,
            @Nullable ConnectionCallback connectionCallback,
            @Nullable Executor onConfigurationExecutor,
            @Nullable OnConfigurationListener onConfigurationListener,
            @Nullable Executor onCommandExecutor,
            @Nullable OnCommandListener onCommandListener,
            @NonNull Semaphore semaphore,
            @NonNull BoundedExponentialBackoff backoff,
            @NonNull AtomicBoolean clientConnectionState); void connect(); boolean isConnected(); void disconnect(); boolean publishTelemetry(@NonNull TelemetryEvent event); void publishDeviceState(byte[] state); }
IotCoreClient { public boolean publishTelemetry(@NonNull TelemetryEvent event) { synchronized (mQueueLock) { int preOfferSize = mTelemetryQueue.size(); if (!mTelemetryQueue.offer(event) || mTelemetryQueue.size() == preOfferSize) { return false; } } mSemaphore.release(); return true; } private  IotCoreClient(
            @NonNull ConnectionParams connectionParams,
            @NonNull KeyPair keyPair,
            @NonNull MqttClient mqttClient,
            @NonNull Queue<TelemetryEvent> telemetryQueue,
            @Nullable Executor connectionCallbackExecutor,
            @Nullable ConnectionCallback connectionCallback,
            @Nullable Executor onConfigurationExecutor,
            @Nullable OnConfigurationListener onConfigurationListener,
            @Nullable Executor onCommandExecutor,
            @Nullable OnCommandListener onCommandListener); @VisibleForTesting  IotCoreClient(
            @NonNull ConnectionParams configuration,
            @NonNull MqttClient mqttClient,
            @NonNull JwtGenerator jwtGenerator,
            @NonNull AtomicBoolean runBackgroundThread,
            @NonNull AtomicReference<byte[]> unsentDeviceState,
            @NonNull Queue<TelemetryEvent> telemetryQueue,
            @Nullable Executor connectionCallbackExecutor,
            @Nullable ConnectionCallback connectionCallback,
            @Nullable Executor onConfigurationExecutor,
            @Nullable OnConfigurationListener onConfigurationListener,
            @Nullable Executor onCommandExecutor,
            @Nullable OnCommandListener onCommandListener,
            @NonNull Semaphore semaphore,
            @NonNull BoundedExponentialBackoff backoff,
            @NonNull AtomicBoolean clientConnectionState); void connect(); boolean isConnected(); void disconnect(); boolean publishTelemetry(@NonNull TelemetryEvent event); void publishDeviceState(byte[] state);  }