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