[ResultStore] update proto file and implement error storage
This CL:
1. Add TelemetryError message to proto definitions.
2. Implements ResultStore#putError() and getError()
3. Updates DataBrokerImpl to put error into result store
Fixes: 197005294
Test: atest CarServiceUnitTest:ResultStoreTest
Test: atest CarServiceUnitTest:DataBrokerTest
Change-Id: I976f69fe9e6ac8617101a182664087e8815d22e7
diff --git a/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerTest.java b/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerTest.java
index 6c41e4b..0b76e48 100644
--- a/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerTest.java
@@ -243,6 +243,26 @@
}
@Test
+ public void testScheduleNextTask_onScriptError_shouldStoreErrorObject() throws Exception {
+ mDataBroker.getTaskQueue().add(mHighPriorityTask);
+ TelemetryProto.TelemetryError.ErrorType errorType =
+ TelemetryProto.TelemetryError.ErrorType.LUA_RUNTIME_ERROR;
+ String errorMessage = "test onError";
+ TelemetryProto.TelemetryError expectedError = TelemetryProto.TelemetryError.newBuilder()
+ .setErrorType(errorType)
+ .setMessage(errorMessage)
+ .build();
+
+ mDataBroker.scheduleNextTask();
+ waitForHandlerThreadToFinish();
+ mFakeScriptExecutor.notifyScriptError(errorType.getNumber(), errorMessage);
+
+ waitForHandlerThreadToFinish();
+ assertThat(mFakeScriptExecutor.getApiInvocationCount()).isEqualTo(1);
+ verify(mMockResultStore).putError(eq(METRICS_CONFIG_FOO.getName()), eq(expectedError));
+ }
+
+ @Test
public void testScheduleNextTask_whenScriptFinishes_shouldStoreFinalResult()
throws Exception {
mData.putBoolean("script is finished", true);
@@ -413,6 +433,15 @@
}
}
+ /** Mocks script finished with error. */
+ public void notifyScriptError(int errorType, String errorMessage) {
+ try {
+ mListener.onError(errorType, errorMessage, null);
+ } catch (RemoteException e) {
+ // nothing to do
+ }
+ }
+
/** Fails the next N invokeScript() call. */
public void failNextApiCalls(int n) {
mFailApi = n;