1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.adservices.service.stats; 18 19 import static org.junit.Assert.assertEquals; 20 21 import android.adservices.common.AdServicesStatusUtils; 22 23 import org.junit.Test; 24 25 /** Unit tests for {@link RunAdBiddingProcessReportedStats}. */ 26 public class RunAdBiddingProcessReportedStatsTest { 27 static final int GET_BUYERS_CUSTOM_AUDIENCE_LATENCY_IN_MILLIS = 10; 28 static final int NUM_BUYERS_REQUESTED = 5; 29 static final int NUM_BUYERS_FETCHED = 3; 30 static final int NUM_OF_ADS_ENTERING_BIDDING = 20; 31 static final int NUM_OF_CAS_ENTERING_BIDDING = 10; 32 static final int NUM_OF_CAS_POSTING_BIDDING = 2; 33 static final float RATIO_OF_CAS_SELECTING_RMKT_ADS = 0.80f; 34 static final int RUN_AD_BIDDING_LATENCY_IN_MILLIS = 10; 35 static final int TOTAL_AD_BIDDING_STAGE_LATENCY_IN_MILLIS = 20; 36 static final int GET_BUYERS_CUSTOM_AUDIENCE_RESULT_CODE = AdServicesStatusUtils.STATUS_SUCCESS; 37 static final int RUN_AD_BIDDING_RESULT_CODE = AdServicesStatusUtils.STATUS_SUCCESS; 38 39 @Test testBuilderCreateSuccess()40 public void testBuilderCreateSuccess() { 41 RunAdBiddingProcessReportedStats stats = 42 RunAdBiddingProcessReportedStats.builder() 43 .setGetBuyersCustomAudienceLatencyInMills( 44 GET_BUYERS_CUSTOM_AUDIENCE_LATENCY_IN_MILLIS) 45 .setGetBuyersCustomAudienceResultCode( 46 GET_BUYERS_CUSTOM_AUDIENCE_RESULT_CODE) 47 .setNumBuyersRequested(NUM_BUYERS_REQUESTED) 48 .setNumBuyersFetched(NUM_BUYERS_FETCHED) 49 .setNumOfAdsEnteringBidding(NUM_OF_ADS_ENTERING_BIDDING) 50 .setNumOfCasEnteringBidding(NUM_OF_CAS_ENTERING_BIDDING) 51 .setNumOfCasPostBidding(NUM_OF_CAS_POSTING_BIDDING) 52 .setRatioOfCasSelectingRmktAds(RATIO_OF_CAS_SELECTING_RMKT_ADS) 53 .setRunAdBiddingLatencyInMillis(RUN_AD_BIDDING_LATENCY_IN_MILLIS) 54 .setRunAdBiddingResultCode(RUN_AD_BIDDING_RESULT_CODE) 55 .setTotalAdBiddingStageLatencyInMillis( 56 TOTAL_AD_BIDDING_STAGE_LATENCY_IN_MILLIS) 57 .build(); 58 assertEquals( 59 GET_BUYERS_CUSTOM_AUDIENCE_LATENCY_IN_MILLIS, 60 stats.getGetBuyersCustomAudienceLatencyInMills()); 61 assertEquals( 62 GET_BUYERS_CUSTOM_AUDIENCE_RESULT_CODE, 63 stats.getGetBuyersCustomAudienceResultCode()); 64 assertEquals(NUM_BUYERS_REQUESTED, stats.getNumBuyersRequested()); 65 assertEquals(NUM_BUYERS_FETCHED, stats.getNumBuyersFetched()); 66 assertEquals(NUM_OF_ADS_ENTERING_BIDDING, stats.getNumOfAdsEnteringBidding()); 67 assertEquals(NUM_OF_CAS_ENTERING_BIDDING, stats.getNumOfCasEnteringBidding()); 68 assertEquals(NUM_OF_CAS_POSTING_BIDDING, stats.getNumOfCasPostBidding()); 69 assertEquals(RATIO_OF_CAS_SELECTING_RMKT_ADS, stats.getRatioOfCasSelectingRmktAds(), 0.0f); 70 assertEquals(RUN_AD_BIDDING_LATENCY_IN_MILLIS, stats.getRunAdBiddingLatencyInMillis()); 71 assertEquals(RUN_AD_BIDDING_RESULT_CODE, stats.getRunAdBiddingResultCode()); 72 assertEquals( 73 TOTAL_AD_BIDDING_STAGE_LATENCY_IN_MILLIS, 74 stats.getTotalAdBiddingStageLatencyInMillis()); 75 } 76 } 77