Pass ResultStore to DataBroker and store interim script results DO NOT MERGE
This CL only stores interim script results. More change will come
once the ScriptExecutorListener API is updated to use PersistableBundle.
Bug: 195422422
Test: atest CarServiceUnitTest:DataBrokerUnitTest
Change-Id: I65d2d77d075bc83b887ad5ec1a2f53f66472cb79
diff --git a/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerUnitTest.java b/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerUnitTest.java
index a458efd..972212c 100644
--- a/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerUnitTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerUnitTest.java
@@ -22,6 +22,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -32,12 +33,14 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
+import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.SystemClock;
import com.android.car.CarPropertyService;
import com.android.car.scriptexecutor.IScriptExecutor;
import com.android.car.scriptexecutor.IScriptExecutorListener;
+import com.android.car.telemetry.ResultStore;
import com.android.car.telemetry.TelemetryProto;
import com.android.car.telemetry.publisher.PublisherFactory;
@@ -95,6 +98,8 @@
private CarPropertyService mMockCarPropertyService;
@Mock
private IBinder mMockScriptExecutorBinder;
+ @Mock
+ private ResultStore mMockResultStore;
@Captor
private ArgumentCaptor<ServiceConnection> mServiceConnectionCaptor;
@@ -106,7 +111,7 @@
// bind service should return true, otherwise broker is disabled
when(mMockContext.bindServiceAsUser(any(), any(), anyInt(), any())).thenReturn(true);
PublisherFactory factory = new PublisherFactory(mMockCarPropertyService);
- mDataBroker = new DataBrokerImpl(mMockContext, factory);
+ mDataBroker = new DataBrokerImpl(mMockContext, factory, mMockResultStore);
mHandler = mDataBroker.getWorkerHandler();
mFakeScriptExecutor = new FakeScriptExecutor();
@@ -195,7 +200,7 @@
mDataBroker.scheduleNextTask(); // start a task
waitForHandlerThreadToFinish();
// end a task, should automatically schedule the next task
- mFakeScriptExecutor.notifyScriptSuccess();
+ mFakeScriptExecutor.notifyScriptSuccess(DATA);
waitForHandlerThreadToFinish();
// verify queue is empty, both tasks are polled and executed
@@ -204,6 +209,23 @@
}
@Test
+ public void testScheduleNextTask_onScriptSuccess_shouldStoreInterimResult() {
+ mDataBroker.getTaskQueue().add(mHighPriorityTask);
+ ArgumentCaptor<PersistableBundle> persistableBundleCaptor =
+ ArgumentCaptor.forClass(PersistableBundle.class);
+
+ mDataBroker.scheduleNextTask();
+ waitForHandlerThreadToFinish();
+ mFakeScriptExecutor.notifyScriptSuccess(new Bundle()); // pass in empty bundle
+
+ assertThat(mFakeScriptExecutor.getApiInvocationCount()).isEqualTo(1);
+ verify(mMockResultStore).putInterimResult(eq(METRICS_CONFIG_FOO.getName()),
+ persistableBundleCaptor.capture());
+ assertThat(persistableBundleCaptor.getValue().toString()).isEqualTo(
+ new PersistableBundle().toString()); // expect empty persistable bundle
+ }
+
+ @Test
public void testScheduleNextTask_whenBindScriptExecutorFailed_shouldDisableBroker() {
mDataBroker.addMetricsConfiguration(METRICS_CONFIG_FOO);
PriorityBlockingQueue<ScriptExecutionTask> taskQueue = mDataBroker.getTaskQueue();
@@ -322,10 +344,10 @@
return null;
}
- /** Mocks script completion. */
- public void notifyScriptSuccess() {
+ /** Mocks script temporary completion. */
+ public void notifyScriptSuccess(Bundle bundle) {
try {
- mListener.onSuccess(new Bundle());
+ mListener.onSuccess(bundle);
} catch (RemoteException e) {
// nothing to do
}