1 /* 2 * Copyright 2022 Google LLC 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 package com.google.android.libraries.mobiledatadownload.internal.logging.testing; 17 18 import static com.google.common.util.concurrent.Futures.immediateFailedFuture; 19 20 import com.google.android.libraries.mobiledatadownload.internal.logging.EventLogger; 21 import com.google.android.libraries.mobiledatadownload.internal.logging.EventLogger.FileGroupStatusWithDetails; 22 import com.google.common.collect.ArrayListMultimap; 23 import com.google.common.util.concurrent.AsyncCallable; 24 import com.google.common.util.concurrent.ListenableFuture; 25 import com.google.mobiledatadownload.LogEnumsProto.MddClientEvent; 26 import com.google.mobiledatadownload.LogEnumsProto.MddDownloadResult; 27 import com.google.mobiledatadownload.LogProto.DataDownloadFileGroupStats; 28 import com.google.mobiledatadownload.LogProto.MddStorageStats; 29 import java.util.ArrayList; 30 import java.util.List; 31 32 /** Fake implementation of {@link EventLogger} for use in tests. */ 33 public final class FakeEventLogger implements EventLogger { 34 35 private final ArrayList<MddClientEvent.Code> loggedCodes = new ArrayList<>(); 36 private final ArrayListMultimap<DataDownloadFileGroupStats, Void> loggedLatencies = 37 ArrayListMultimap.create(); 38 private final ArrayListMultimap<DataDownloadFileGroupStats, Void> loggedNewConfigReceived = 39 ArrayListMultimap.create(); 40 private final List<Void> loggedMddLibApiResultLog = new ArrayList<>(); 41 private final ArrayList<DataDownloadFileGroupStats> loggedMddQueryStats = new ArrayList<>(); 42 43 @Override logEventSampled(MddClientEvent.Code eventCode)44 public void logEventSampled(MddClientEvent.Code eventCode) { 45 loggedCodes.add(eventCode); 46 } 47 48 @Override logEventSampled( MddClientEvent.Code eventCode, String fileGroupName, int fileGroupVersionNumber, long buildId, String variantId)49 public void logEventSampled( 50 MddClientEvent.Code eventCode, 51 String fileGroupName, 52 int fileGroupVersionNumber, 53 long buildId, 54 String variantId) { 55 loggedCodes.add(eventCode); 56 } 57 58 @Override logEventAfterSample(MddClientEvent.Code eventCode, int sampleInterval)59 public void logEventAfterSample(MddClientEvent.Code eventCode, int sampleInterval) { 60 loggedCodes.add(eventCode); 61 } 62 63 @Override logMddFileGroupStats( AsyncCallable<List<FileGroupStatusWithDetails>> buildFileGroupStats)64 public ListenableFuture<Void> logMddFileGroupStats( 65 AsyncCallable<List<FileGroupStatusWithDetails>> buildFileGroupStats) { 66 return immediateFailedFuture( 67 new UnsupportedOperationException("This method is not implemented in the fake yet.")); 68 } 69 70 @Override logMddApiCallStats(DataDownloadFileGroupStats fileGroupDetails, Void apiCallStats)71 public void logMddApiCallStats(DataDownloadFileGroupStats fileGroupDetails, Void apiCallStats) { 72 throw new UnsupportedOperationException("This method is not implemented in the fake yet."); 73 } 74 75 @Override logMddLibApiResultLog(Void mddLibApiResultLog)76 public void logMddLibApiResultLog(Void mddLibApiResultLog) { 77 loggedMddLibApiResultLog.add(mddLibApiResultLog); 78 } 79 getLoggedMddLibApiResultLogs()80 public List<Void> getLoggedMddLibApiResultLogs() { 81 return loggedMddLibApiResultLog; 82 } 83 84 @Override logMddStorageStats( AsyncCallable<MddStorageStats> buildMddStorageStats)85 public ListenableFuture<Void> logMddStorageStats( 86 AsyncCallable<MddStorageStats> buildMddStorageStats) { 87 return immediateFailedFuture( 88 new UnsupportedOperationException("This method is not implemented in the fake yet.")); 89 } 90 91 @Override logMddNetworkStats(AsyncCallable<Void> buildMddNetworkStats)92 public ListenableFuture<Void> logMddNetworkStats(AsyncCallable<Void> buildMddNetworkStats) { 93 return immediateFailedFuture( 94 new UnsupportedOperationException("This method is not implemented in the fake yet.")); 95 } 96 97 @Override logMddDataDownloadFileExpirationEvent(int eventCode, int count)98 public void logMddDataDownloadFileExpirationEvent(int eventCode, int count) { 99 throw new UnsupportedOperationException("This method is not implemented in the fake yet."); 100 } 101 102 @Override logMddNetworkSavings( DataDownloadFileGroupStats fileGroupDetails, int code, long fullFileSize, long downloadedFileSize, String fileId, int deltaIndex)103 public void logMddNetworkSavings( 104 DataDownloadFileGroupStats fileGroupDetails, 105 int code, 106 long fullFileSize, 107 long downloadedFileSize, 108 String fileId, 109 int deltaIndex) { 110 throw new UnsupportedOperationException("This method is not implemented in the fake yet."); 111 } 112 113 @Override logMddDownloadResult( MddDownloadResult.Code code, DataDownloadFileGroupStats fileGroupDetails)114 public void logMddDownloadResult( 115 MddDownloadResult.Code code, DataDownloadFileGroupStats fileGroupDetails) { 116 throw new UnsupportedOperationException("This method is not implemented in the fake yet."); 117 } 118 119 @Override logMddQueryStats(DataDownloadFileGroupStats fileGroupDetails)120 public void logMddQueryStats(DataDownloadFileGroupStats fileGroupDetails) { 121 loggedMddQueryStats.add(fileGroupDetails); 122 } 123 124 @Override logMddAndroidSharingLog(Void event)125 public void logMddAndroidSharingLog(Void event) { 126 throw new UnsupportedOperationException("This method is not implemented in the fake yet."); 127 } 128 129 @Override logMddDownloadLatency( DataDownloadFileGroupStats fileGroupStats, Void downloadLatency)130 public void logMddDownloadLatency( 131 DataDownloadFileGroupStats fileGroupStats, Void downloadLatency) { 132 loggedLatencies.put(fileGroupStats, downloadLatency); 133 } 134 135 @Override logMddUsageEvent(DataDownloadFileGroupStats fileGroupDetails, Void usageEventLog)136 public void logMddUsageEvent(DataDownloadFileGroupStats fileGroupDetails, Void usageEventLog) { 137 throw new UnsupportedOperationException("This method is not implemented in the fake yet."); 138 } 139 140 @Override logNewConfigReceived( DataDownloadFileGroupStats fileGroupDetails, Void newConfigReceivedInfo)141 public void logNewConfigReceived( 142 DataDownloadFileGroupStats fileGroupDetails, Void newConfigReceivedInfo) { 143 loggedNewConfigReceived.put(fileGroupDetails, newConfigReceivedInfo); 144 } 145 reset()146 public void reset() { 147 loggedCodes.clear(); 148 loggedLatencies.clear(); 149 loggedMddQueryStats.clear(); 150 loggedNewConfigReceived.clear(); 151 loggedMddLibApiResultLog.clear(); 152 } 153 getLoggedNewConfigReceived()154 public ArrayListMultimap<DataDownloadFileGroupStats, Void> getLoggedNewConfigReceived() { 155 return loggedNewConfigReceived; 156 } 157 getLoggedCodes()158 public List<MddClientEvent.Code> getLoggedCodes() { 159 return loggedCodes; 160 } 161 getLoggedLatencies()162 public ArrayListMultimap<DataDownloadFileGroupStats, Void> getLoggedLatencies() { 163 return loggedLatencies; 164 } 165 getLoggedMddQueryStats()166 public ArrayList<DataDownloadFileGroupStats> getLoggedMddQueryStats() { 167 return loggedMddQueryStats; 168 } 169 } 170