/// <summary> /// Returns the number of errors recorded for the given metric. /// </summary> /// <param name="errorType">The type of the error recorded.</param> /// <param name="pingName">Represents the name of the ping to retrieve the metric for. /// Defaults to the first value in `sendInPings`.</param> /// <returns>the number of errors recorded for the metric.</returns> public Int32 TestGetNumRecordedErrors(Testing.ErrorType errorType, string pingName = null) { Dispatchers.AssertInTestingMode(); string ping = pingName ?? sendInPings[0]; switch (submetric) { case BooleanMetricType _: { return(LibGleanFFI.glean_labeled_boolean_test_get_num_recorded_errors(handle, (int)errorType, ping)); } case CounterMetricType _: { return(LibGleanFFI.glean_labeled_counter_test_get_num_recorded_errors(handle, (int)errorType, ping)); } case StringMetricType _: { return(LibGleanFFI.glean_labeled_string_test_get_num_recorded_errors(handle, (int)errorType, ping)); } default: throw new InvalidOperationException("Can not return errors for this metric type"); } }
/// <summary> /// Tests whether a value is stored for the metric for testing purposes only. This function will /// attempt to await the last task (if any) writing to the the metric's storage engine before /// returning a value. /// </summary> /// <param name="pingName">represents the name of the ping to retrieve the metric for Defaults /// to the first value in `sendInPings`</param> /// <returns>true if metric value exists, otherwise false</returns> public bool TestHasValue(string pingName = null) { Dispatchers.AssertInTestingMode(); string ping = pingName ?? sendInPings[0]; return(LibGleanFFI.glean_string_test_has_value(this.handle, ping) != 0); }
/** * Returns the number of errors recorded for the given metric. * * @param errorType The type of the error recorded. * @param pingName represents the name of the ping to retrieve the metric for. * Defaults to the first value in `sendInPings`. * @return the number of errors recorded for the metric. */ public Int32 TestGetNumRecordedErrors(Testing.ErrorType errorType, string pingName = null) { Dispatchers.AssertInTestingMode(); string ping = pingName ?? sendInPings[0]; return(LibGleanFFI.glean_string_test_get_num_recorded_errors( this.handle, (int)errorType, ping )); }
/// <summary> /// Returns the stored value for testing purposes only. This function will attempt to await the /// last task (if any) writing to the the metric's storage engine before returning a value. /// @throws [NullPointerException] if no value is stored /// </summary> /// <param name="pingName">represents the name of the ping to retrieve the metric for. /// Defaults to the first value in `sendInPings`</param> /// <returns>value of the stored metric</returns> /// <exception cref="System.NullReferenceException">Thrown when the metric contains no value</exception> public string TestGetValue(string pingName = null) { Dispatchers.AssertInTestingMode(); if (!TestHasValue(pingName)) { throw new NullReferenceException(); } string ping = pingName ?? sendInPings[0]; return(LibGleanFFI.glean_string_test_get_value(this.handle, ping).AsString()); }
/// <summary> /// Returns the stored value for testing purposes only. This function will attempt to await the /// last task (if any) writing to the the metric's storage engine before returning a value. /// </summary> /// <param name="pingName">represents the name of the ping to retrieve the metric for. /// Defaults to the first value in `sendInPings`</param> /// <returns>value of the stored metric</returns> /// <exception cref="System.NullReferenceException">Thrown when the metric contains no value</exception> public DistributionData TestGetValue(string pingName = null) { Dispatchers.AssertInTestingMode(); if (!TestHasValue(pingName)) { throw new NullReferenceException(); } string ping = pingName ?? sendInPings[0]; return(DistributionData.FromJsonString( LibGleanFFI.glean_timing_distribution_test_get_value_as_json_string(handle, ping).AsString())); }
/// <summary> /// Returns the stored value for testing purposes only. This function will attempt to await the /// last task(if any) writing to the the metric's storage engine before returning a value. /// </summary> /// <param name="pingName">represents the name of the ping to retrieve the metric for. /// Defaults to the first value in `sendInPings`.</param> /// <returns>value of the stored metric</returns> /// <exception cref="System.NullReferenceException">Thrown when the metric contains no value</exception> public string[] TestGetValue(string pingName = null) { Dispatchers.AssertInTestingMode(); if (!TestHasValue(pingName)) { throw new NullReferenceException(); } string ping = pingName ?? sendInPings[0]; JsonDocument jsonPayload = JsonDocument.Parse( LibGleanFFI.glean_string_list_test_get_value_as_json_string(this.handle, ping).AsString() ); JsonElement root = jsonPayload.RootElement; return(JsonSerializer.Deserialize <string[]>(root.ToString())); }
/// <summary> /// Returns the stored value for testing purposes only. This function will attempt to await the /// last task (if any) writing to the the metric's storage engine before returning a value. /// @throws [NullPointerException] if no value is stored /// </summary> /// <param name="pingName">represents the name of the ping to retrieve the metric for. /// Defaults to the first value in `sendInPings`</param> /// <returns>value of the stored metric</returns> /// <exception cref="System.NullReferenceException">Thrown when the metric contains no value</exception> public JweData TestGetValue(string pingName = null) { Dispatchers.AssertInTestingMode(); if (!TestHasValue(pingName)) { throw new NullReferenceException(); } string ping = pingName ?? sendInPings[0]; JsonDocument jsonPayload = JsonDocument.Parse( LibGleanFFI.glean_jwe_test_get_value_as_json_string(this.handle, ping).AsString() ); JsonElement root = jsonPayload.RootElement; return(new JweData( root.GetProperty("header").GetString(), root.GetProperty("key").GetString(), root.GetProperty("init_vector").GetString(), root.GetProperty("cipher_text").GetString(), root.GetProperty("auth_tag").GetString() )); }