Merge "Update framework from jetpack." into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b7e36190f6
@@ -96,6 +96,17 @@ public final class AppSearchBatchResult<KeyType, ValueType> {
|
||||
return Collections.unmodifiableMap(mAll);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that this {@link AppSearchBatchResult} has no failures.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void checkSuccess() {
|
||||
if (!isSuccess()) {
|
||||
throw new IllegalStateException("AppSearchBatchResult has failures: " + this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String toString() {
|
||||
|
||||
@@ -71,7 +71,7 @@ public final class SchemaMigrationUtil {
|
||||
|
||||
/**
|
||||
* Checks the setSchema() call won't delete any types or has incompatible types after all {@link
|
||||
* Migrator} has been triggered..
|
||||
* Migrator} has been triggered.
|
||||
*/
|
||||
public static void checkDeletedAndIncompatibleAfterMigration(
|
||||
@NonNull SetSchemaResponse setSchemaResponse, @NonNull Set<String> activeMigrators)
|
||||
|
||||
@@ -363,6 +363,7 @@ public class AppSearchManagerService extends SystemService {
|
||||
schemasVisibleToPackages.put(entry.getKey(), packageIdentifiers);
|
||||
}
|
||||
instance = mAppSearchUserInstanceManager.getUserInstance(targetUser);
|
||||
// TODO(b/173532925): Implement logging for statsBuilder
|
||||
SetSchemaResponse setSchemaResponse = instance.getAppSearchImpl().setSchema(
|
||||
packageName,
|
||||
databaseName,
|
||||
@@ -371,7 +372,8 @@ public class AppSearchManagerService extends SystemService {
|
||||
schemasNotDisplayedBySystem,
|
||||
schemasVisibleToPackages,
|
||||
forceOverride,
|
||||
schemaVersion);
|
||||
schemaVersion,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
++operationSuccessCount;
|
||||
invokeCallbackOnResult(callback,
|
||||
AppSearchResult.newSuccessfulResult(setSchemaResponse.getBundle()));
|
||||
@@ -816,8 +818,10 @@ public class AppSearchManagerService extends SystemService {
|
||||
|
||||
AppSearchUserInstance instance =
|
||||
mAppSearchUserInstanceManager.getUserInstance(targetUser);
|
||||
// TODO(b/173532925): Implement logging for statsBuilder
|
||||
SearchResultPage searchResultPage =
|
||||
instance.getAppSearchImpl().getNextPage(packageName, nextPageToken);
|
||||
instance.getAppSearchImpl().getNextPage(
|
||||
packageName, nextPageToken, /*statsBuilder=*/ null);
|
||||
invokeCallbackOnResult(
|
||||
callback,
|
||||
AppSearchResult.newSuccessfulResult(searchResultPage.getBundle()));
|
||||
@@ -898,8 +902,11 @@ public class AppSearchManagerService extends SystemService {
|
||||
outputStream, searchResultPage.getResults().get(i)
|
||||
.getGenericDocument().getBundle());
|
||||
}
|
||||
// TODO(b/173532925): Implement logging for statsBuilder
|
||||
searchResultPage = instance.getAppSearchImpl().getNextPage(
|
||||
packageName, searchResultPage.getNextPageToken());
|
||||
packageName,
|
||||
searchResultPage.getNextPageToken(),
|
||||
/*statsBuilder=*/ null);
|
||||
}
|
||||
}
|
||||
invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null));
|
||||
|
||||
@@ -59,6 +59,7 @@ import com.android.server.appsearch.external.localstorage.stats.OptimizeStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.RemoveStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SearchStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SetSchemaStats;
|
||||
import com.android.server.appsearch.external.localstorage.visibilitystore.VisibilityStore;
|
||||
|
||||
import com.google.android.icing.IcingSearchEngine;
|
||||
@@ -393,6 +394,7 @@ public final class AppSearchImpl implements Closeable {
|
||||
* @param forceOverride Whether to force-apply the schema even if it is incompatible. Documents
|
||||
* which do not comply with the new schema will be deleted.
|
||||
* @param version The overall version number of the request.
|
||||
* @param setSchemaStatsBuilder Builder for {@link SetSchemaStats} to hold stats for setSchema
|
||||
* @return The response contains deleted schema types and incompatible schema types of this
|
||||
* call.
|
||||
* @throws AppSearchException On IcingSearchEngine error. If the status code is
|
||||
@@ -408,7 +410,8 @@ public final class AppSearchImpl implements Closeable {
|
||||
@NonNull List<String> schemasNotDisplayedBySystem,
|
||||
@NonNull Map<String, List<PackageIdentifier>> schemasVisibleToPackages,
|
||||
boolean forceOverride,
|
||||
int version)
|
||||
int version,
|
||||
@Nullable SetSchemaStats.Builder setSchemaStatsBuilder)
|
||||
throws AppSearchException {
|
||||
mReadWriteLock.writeLock().lock();
|
||||
try {
|
||||
@@ -438,6 +441,12 @@ public final class AppSearchImpl implements Closeable {
|
||||
mLogUtil.piiTrace(
|
||||
"setSchema, response", setSchemaResultProto.getStatus(), setSchemaResultProto);
|
||||
|
||||
if (setSchemaStatsBuilder != null) {
|
||||
setSchemaStatsBuilder.setStatusCode(
|
||||
statusProtoToResultCode(setSchemaResultProto.getStatus()));
|
||||
AppSearchLoggerHelper.copyNativeStats(setSchemaResultProto, setSchemaStatsBuilder);
|
||||
}
|
||||
|
||||
// Determine whether it succeeded.
|
||||
try {
|
||||
checkSuccess(setSchemaResultProto.getStatus());
|
||||
@@ -1127,8 +1136,13 @@ public final class AppSearchImpl implements Closeable {
|
||||
* @throws AppSearchException on IcingSearchEngine error or if can't advance on nextPageToken.
|
||||
*/
|
||||
@NonNull
|
||||
public SearchResultPage getNextPage(@NonNull String packageName, long nextPageToken)
|
||||
public SearchResultPage getNextPage(
|
||||
@NonNull String packageName,
|
||||
long nextPageToken,
|
||||
@Nullable SearchStats.Builder statsBuilder)
|
||||
throws AppSearchException {
|
||||
long totalLatencyStartMillis = SystemClock.elapsedRealtime();
|
||||
|
||||
mReadWriteLock.readLock().lock();
|
||||
try {
|
||||
throwIfClosedLocked();
|
||||
@@ -1137,6 +1151,13 @@ public final class AppSearchImpl implements Closeable {
|
||||
checkNextPageToken(packageName, nextPageToken);
|
||||
SearchResultProto searchResultProto =
|
||||
mIcingSearchEngineLocked.getNextPage(nextPageToken);
|
||||
|
||||
if (statsBuilder != null) {
|
||||
statsBuilder.setStatusCode(statusProtoToResultCode(searchResultProto.getStatus()));
|
||||
AppSearchLoggerHelper.copyNativeStats(
|
||||
searchResultProto.getQueryStats(), statsBuilder);
|
||||
}
|
||||
|
||||
mLogUtil.piiTrace(
|
||||
"getNextPage, response",
|
||||
searchResultProto.getResultsCount(),
|
||||
@@ -1152,9 +1173,22 @@ public final class AppSearchImpl implements Closeable {
|
||||
mNextPageTokensLocked.get(packageName).remove(nextPageToken);
|
||||
}
|
||||
}
|
||||
return rewriteSearchResultProto(searchResultProto, mSchemaMapLocked);
|
||||
long rewriteSearchResultLatencyStartMillis = SystemClock.elapsedRealtime();
|
||||
SearchResultPage resultPage =
|
||||
rewriteSearchResultProto(searchResultProto, mSchemaMapLocked);
|
||||
if (statsBuilder != null) {
|
||||
statsBuilder.setRewriteSearchResultLatencyMillis(
|
||||
(int)
|
||||
(SystemClock.elapsedRealtime()
|
||||
- rewriteSearchResultLatencyStartMillis));
|
||||
}
|
||||
return resultPage;
|
||||
} finally {
|
||||
mReadWriteLock.readLock().unlock();
|
||||
if (statsBuilder != null) {
|
||||
statsBuilder.setTotalLatencyMillis(
|
||||
(int) (SystemClock.elapsedRealtime() - totalLatencyStartMillis));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1334,7 +1368,7 @@ public final class AppSearchImpl implements Closeable {
|
||||
statusProtoToResultCode(deleteResultProto.getStatus()));
|
||||
// TODO(b/187206766) also log query stats here once IcingLib returns it
|
||||
AppSearchLoggerHelper.copyNativeStats(
|
||||
deleteResultProto.getDeleteStats(), removeStatsBuilder);
|
||||
deleteResultProto.getDeleteByQueryStats(), removeStatsBuilder);
|
||||
}
|
||||
|
||||
// It seems that the caller wants to get success if the data matching the query is
|
||||
@@ -1343,7 +1377,8 @@ public final class AppSearchImpl implements Closeable {
|
||||
deleteResultProto.getStatus(), StatusProto.Code.OK, StatusProto.Code.NOT_FOUND);
|
||||
|
||||
// Update derived maps
|
||||
int numDocumentsDeleted = deleteResultProto.getDeleteStats().getNumDocumentsDeleted();
|
||||
int numDocumentsDeleted =
|
||||
deleteResultProto.getDeleteByQueryStats().getNumDocumentsDeleted();
|
||||
updateDocumentCountAfterRemovalLocked(packageName, numDocumentsDeleted);
|
||||
} finally {
|
||||
mReadWriteLock.writeLock().unlock();
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.android.server.appsearch.external.localstorage.stats.OptimizeStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.RemoveStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SearchStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SetSchemaStats;
|
||||
|
||||
/**
|
||||
* An interface for implementing client-defined logging AppSearch operations stats.
|
||||
@@ -54,5 +55,8 @@ public interface AppSearchLogger {
|
||||
/** Logs {@link OptimizeStats} */
|
||||
void logStats(@NonNull OptimizeStats stats);
|
||||
|
||||
/** Logs {@link SetSchemaStats} */
|
||||
void logStats(@NonNull SetSchemaStats stats);
|
||||
|
||||
// TODO(b/173532925) Add remaining logStats once we add all the stats.
|
||||
}
|
||||
|
||||
@@ -23,12 +23,15 @@ import com.android.server.appsearch.external.localstorage.stats.OptimizeStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.RemoveStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SearchStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SetSchemaStats;
|
||||
|
||||
import com.google.android.icing.proto.DeleteByQueryStatsProto;
|
||||
import com.google.android.icing.proto.DeleteStatsProto;
|
||||
import com.google.android.icing.proto.InitializeStatsProto;
|
||||
import com.google.android.icing.proto.OptimizeStatsProto;
|
||||
import com.google.android.icing.proto.PutDocumentStatsProto;
|
||||
import com.google.android.icing.proto.QueryStatsProto;
|
||||
import com.google.android.icing.proto.SetSchemaResultProto;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -141,6 +144,26 @@ public final class AppSearchLoggerHelper {
|
||||
.setDeletedDocumentCount(fromNativeStats.getNumDocumentsDeleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies native DeleteByQuery stats to builder.
|
||||
*
|
||||
* @param fromNativeStats Stats copied from.
|
||||
* @param toStatsBuilder Stats copied to.
|
||||
*/
|
||||
static void copyNativeStats(
|
||||
@NonNull DeleteByQueryStatsProto fromNativeStats,
|
||||
@NonNull RemoveStats.Builder toStatsBuilder) {
|
||||
Objects.requireNonNull(fromNativeStats);
|
||||
Objects.requireNonNull(toStatsBuilder);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
int deleteType = DeleteStatsProto.DeleteType.Code.DEPRECATED_QUERY.getNumber();
|
||||
toStatsBuilder
|
||||
.setNativeLatencyMillis(fromNativeStats.getLatencyMs())
|
||||
.setDeleteType(deleteType)
|
||||
.setDeletedDocumentCount(fromNativeStats.getNumDocumentsDeleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies native {@link OptimizeStatsProto} to builder.
|
||||
*
|
||||
@@ -164,4 +187,25 @@ public final class AppSearchLoggerHelper {
|
||||
.setStorageSizeAfterBytes(fromNativeStats.getStorageSizeAfter())
|
||||
.setTimeSinceLastOptimizeMillis(fromNativeStats.getTimeSinceLastOptimizeMs());
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy SetSchema result stats to builder.
|
||||
*
|
||||
* @param fromProto Stats copied from.
|
||||
* @param toStatsBuilder Stats copied to.
|
||||
*/
|
||||
static void copyNativeStats(
|
||||
@NonNull SetSchemaResultProto fromProto,
|
||||
@NonNull SetSchemaStats.Builder toStatsBuilder) {
|
||||
Objects.requireNonNull(fromProto);
|
||||
Objects.requireNonNull(toStatsBuilder);
|
||||
toStatsBuilder
|
||||
.setNewTypeCount(fromProto.getNewSchemaTypesCount())
|
||||
.setDeletedTypeCount(fromProto.getDeletedSchemaTypesCount())
|
||||
.setCompatibleTypeChangeCount(fromProto.getFullyCompatibleChangedSchemaTypesCount())
|
||||
.setIndexIncompatibleTypeChangeCount(
|
||||
fromProto.getIndexIncompatibleChangedSchemaTypesCount())
|
||||
.setBackwardsIncompatibleTypeChangeCount(
|
||||
fromProto.getIncompatibleSchemaTypesCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public final class SearchStats {
|
||||
VISIBILITY_SCOPE_LOCAL,
|
||||
// Searches the global documents. Including platform surfaceable and 3p-access.
|
||||
VISIBILITY_SCOPE_GLOBAL,
|
||||
VISIBILITY_SCOPE_UNKNOWN,
|
||||
// TODO(b/173532925) Add THIRD_PARTY_ACCESS once we can distinguish platform
|
||||
// surfaceable from 3p access(right both of them are categorized as
|
||||
// VISIBILITY_SCOPE_GLOBAL)
|
||||
@@ -51,6 +52,7 @@ public final class SearchStats {
|
||||
public static final int VISIBILITY_SCOPE_LOCAL = 1;
|
||||
// Searches the global documents. Including platform surfaceable and 3p-access.
|
||||
public static final int VISIBILITY_SCOPE_GLOBAL = 2;
|
||||
public static final int VISIBILITY_SCOPE_UNKNOWN = 3;
|
||||
|
||||
// TODO(b/173532925): Add a field searchType to indicate where the search is used(normal
|
||||
// query vs in removeByQuery vs during migration)
|
||||
|
||||
@@ -47,9 +47,6 @@ public final class SetSchemaStats {
|
||||
|
||||
private final int mTotalLatencyMillis;
|
||||
|
||||
/** Overall time used for the native function call. */
|
||||
private final int mNativeLatencyMillis;
|
||||
|
||||
/** Number of newly added schema types. */
|
||||
private final int mNewTypeCount;
|
||||
|
||||
@@ -72,7 +69,6 @@ public final class SetSchemaStats {
|
||||
mStatusCode = builder.mStatusCode;
|
||||
mSchemaMigrationStats = builder.mSchemaMigrationStats;
|
||||
mTotalLatencyMillis = builder.mTotalLatencyMillis;
|
||||
mNativeLatencyMillis = builder.mNativeLatencyMillis;
|
||||
mNewTypeCount = builder.mNewTypeCount;
|
||||
mDeletedTypeCount = builder.mDeletedTypeCount;
|
||||
mCompatibleTypeChangeCount = builder.mCompatibleTypeChangeCount;
|
||||
@@ -112,11 +108,6 @@ public final class SetSchemaStats {
|
||||
return mTotalLatencyMillis;
|
||||
}
|
||||
|
||||
/** Returns overall time used for the native function call. */
|
||||
public int getNativeLatencyMillis() {
|
||||
return mNativeLatencyMillis;
|
||||
}
|
||||
|
||||
/** Returns number of newly added schema types. */
|
||||
public int getNewTypeCount() {
|
||||
return mNewTypeCount;
|
||||
@@ -159,7 +150,6 @@ public final class SetSchemaStats {
|
||||
@AppSearchResult.ResultCode int mStatusCode;
|
||||
@Nullable SchemaMigrationStats mSchemaMigrationStats;
|
||||
int mTotalLatencyMillis;
|
||||
int mNativeLatencyMillis;
|
||||
int mNewTypeCount;
|
||||
int mDeletedTypeCount;
|
||||
int mCompatibleTypeChangeCount;
|
||||
@@ -193,13 +183,6 @@ public final class SetSchemaStats {
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Sets native latency in milliseconds. */
|
||||
@NonNull
|
||||
public Builder setNativeLatencyMillis(int nativeLatencyMillis) {
|
||||
mNativeLatencyMillis = nativeLatencyMillis;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Sets number of new types. */
|
||||
@NonNull
|
||||
public Builder setNewTypeCount(int newTypeCount) {
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.android.server.appsearch.external.localstorage.stats.OptimizeStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.RemoveStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SearchStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SetSchemaStats;
|
||||
import com.android.server.appsearch.util.PackageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -180,6 +181,11 @@ public final class PlatformLogger implements AppSearchLogger {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logStats(@NonNull SetSchemaStats stats) {
|
||||
// TODO(b/173532925): Log stats
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes cached UID for package.
|
||||
*
|
||||
|
||||
@@ -126,7 +126,8 @@ public class VisibilityStoreImpl implements VisibilityStore {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ SCHEMA_VERSION);
|
||||
/*version=*/ SCHEMA_VERSION,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
}
|
||||
|
||||
// Populate visibility settings set
|
||||
|
||||
@@ -1 +1 @@
|
||||
Ie04f1ecc033faae8085afcb51eb9e40a298998d5
|
||||
bd53b062816070b64feb992c2bf58f3afa3d420e
|
||||
|
||||
@@ -28,6 +28,7 @@ java_library {
|
||||
"framework",
|
||||
"framework-appsearch",
|
||||
"guava",
|
||||
"service-appsearch",
|
||||
"truth-prebuilt",
|
||||
],
|
||||
visibility: [
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.android.server.appsearch.testing;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.appsearch.AppSearchBatchResult;
|
||||
import android.app.appsearch.AppSearchSessionShim;
|
||||
import android.app.appsearch.GenericDocument;
|
||||
@@ -26,12 +28,66 @@ import android.app.appsearch.GetByDocumentIdRequest;
|
||||
import android.app.appsearch.SearchResult;
|
||||
import android.app.appsearch.SearchResultsShim;
|
||||
|
||||
import com.android.server.appsearch.external.localstorage.AppSearchLogger;
|
||||
import com.android.server.appsearch.external.localstorage.stats.CallStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.InitializeStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.OptimizeStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.RemoveStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SearchStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SetSchemaStats;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class AppSearchTestUtils {
|
||||
// Non-thread-safe logger implementation for testing
|
||||
public static class TestLogger implements AppSearchLogger {
|
||||
@Nullable public CallStats mCallStats;
|
||||
@Nullable public PutDocumentStats mPutDocumentStats;
|
||||
@Nullable public InitializeStats mInitializeStats;
|
||||
@Nullable public SearchStats mSearchStats;
|
||||
@Nullable public RemoveStats mRemoveStats;
|
||||
@Nullable public OptimizeStats mOptimizeStats;
|
||||
@Nullable public SetSchemaStats mSetSchemaStats;
|
||||
|
||||
@Override
|
||||
public void logStats(@NonNull CallStats stats) {
|
||||
mCallStats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logStats(@NonNull PutDocumentStats stats) {
|
||||
mPutDocumentStats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logStats(@NonNull InitializeStats stats) {
|
||||
mInitializeStats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logStats(@NonNull SearchStats stats) {
|
||||
mSearchStats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logStats(@NonNull RemoveStats stats) {
|
||||
mRemoveStats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logStats(@NonNull OptimizeStats stats) {
|
||||
mOptimizeStats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logStats(@NonNull SetSchemaStats stats) {
|
||||
mSetSchemaStats = stats;
|
||||
}
|
||||
}
|
||||
|
||||
public static <K, V> AppSearchBatchResult<K, V> checkIsBatchResultSuccess(
|
||||
Future<AppSearchBatchResult<K, V>> future) throws Exception {
|
||||
|
||||
@@ -62,18 +62,4 @@ public class GenericDocumentTest {
|
||||
assertThat(outDoc.getPropertyDocument("propDocument").getPropertyBytesArray("propBytes"))
|
||||
.isEqualTo(new byte[][] {{3, 4}});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutLargeDocument_exceedLimit() throws Exception {
|
||||
// Create a String property that has a very large property.
|
||||
char[] chars = new char[10_000_000];
|
||||
String property = new StringBuilder().append(chars).append("the end.").toString();
|
||||
|
||||
GenericDocument doc =
|
||||
new GenericDocument.Builder<>("namespace", "id1", "schema1")
|
||||
.setPropertyString("propString", property)
|
||||
.build();
|
||||
|
||||
assertThat(doc.getPropertyString("propString")).isEqualTo(property);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,8 @@ public class AppSearchImplPlatformTest {
|
||||
"schema1",
|
||||
ImmutableList.of(new PackageIdentifier(packageNameFoo, sha256CertFoo))),
|
||||
/*forceOverride=*/ false,
|
||||
/*schemaVersion=*/ 0);
|
||||
/*schemaVersion=*/ 0,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
|
||||
// "schema1" is platform hidden now and package visible to package1
|
||||
assertThat(mVisibilityStore.isSchemaSearchableByCaller(
|
||||
@@ -167,7 +168,8 @@ public class AppSearchImplPlatformTest {
|
||||
"schema1",
|
||||
ImmutableList.of(new PackageIdentifier(packageNameFoo, sha256CertFoo))),
|
||||
/*forceOverride=*/ false,
|
||||
/*schemaVersion=*/ 0);
|
||||
/*schemaVersion=*/ 0,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
|
||||
// Check that "schema1" still has the same visibility settings
|
||||
SystemUtil.runWithShellPermissionIdentity(() -> assertThat(
|
||||
@@ -241,7 +243,8 @@ public class AppSearchImplPlatformTest {
|
||||
"schema1",
|
||||
ImmutableList.of(new PackageIdentifier(packageNameFoo, sha256CertFoo))),
|
||||
/*forceOverride=*/ false,
|
||||
/*schemaVersion=*/ 0);
|
||||
/*schemaVersion=*/ 0,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
|
||||
// "schema1" is platform hidden now and package accessible
|
||||
assertThat(mVisibilityStore.isSchemaSearchableByCaller(
|
||||
@@ -269,7 +272,8 @@ public class AppSearchImplPlatformTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ true,
|
||||
/*schemaVersion=*/ 0);
|
||||
/*schemaVersion=*/ 0,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
|
||||
// Check that "schema1" is no longer considered platform hidden or package accessible
|
||||
assertThat(mVisibilityStore.isSchemaSearchableByCaller(
|
||||
@@ -298,7 +302,8 @@ public class AppSearchImplPlatformTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*schemaVersion=*/ 0);
|
||||
/*schemaVersion=*/ 0,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
|
||||
assertThat(mVisibilityStore.isSchemaSearchableByCaller(
|
||||
"package",
|
||||
@@ -333,7 +338,8 @@ public class AppSearchImplPlatformTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*schemaVersion=*/ 0);
|
||||
/*schemaVersion=*/ 0,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
|
||||
assertThat(mVisibilityStore.isSchemaSearchableByCaller(
|
||||
"package",
|
||||
@@ -361,7 +367,8 @@ public class AppSearchImplPlatformTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.singletonList("Schema"),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*schemaVersion=*/ 0);
|
||||
/*schemaVersion=*/ 0,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
|
||||
assertThat(mVisibilityStore.isSchemaSearchableByCaller(
|
||||
"package",
|
||||
@@ -390,7 +397,8 @@ public class AppSearchImplPlatformTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*schemaVersion=*/ 0);
|
||||
/*schemaVersion=*/ 0,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
assertThat(mVisibilityStore
|
||||
.isSchemaSearchableByCaller(
|
||||
"package",
|
||||
@@ -431,7 +439,8 @@ public class AppSearchImplPlatformTest {
|
||||
"Schema",
|
||||
ImmutableList.of(new PackageIdentifier(packageNameFoo, sha256CertFoo))),
|
||||
/*forceOverride=*/ false,
|
||||
/*schemaVersion=*/ 0);
|
||||
/*schemaVersion=*/ 0,
|
||||
/*setSchemaStatsBuilder=*/ null);
|
||||
assertThat(mVisibilityStore
|
||||
.isSchemaSearchableByCaller(
|
||||
"package",
|
||||
|
||||
@@ -76,13 +76,14 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class AppSearchImplTest {
|
||||
@Rule public TemporaryFolder mTemporaryFolder = new TemporaryFolder();
|
||||
private AppSearchImpl mAppSearchImpl;
|
||||
/**
|
||||
* Always trigger optimize in this class. OptimizeStrategy will be tested in its own test class.
|
||||
*/
|
||||
private static final OptimizeStrategy ALWAYS_OPTIMIZE = optimizeInfo -> true;
|
||||
|
||||
@Rule public TemporaryFolder mTemporaryFolder = new TemporaryFolder();
|
||||
private AppSearchImpl mAppSearchImpl;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mAppSearchImpl =
|
||||
@@ -439,7 +440,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert a document and then remove it to generate garbage.
|
||||
GenericDocument document = new GenericDocument.Builder<>("namespace", "id", "type").build();
|
||||
@@ -499,7 +501,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert a valid doc
|
||||
GenericDocument validDoc =
|
||||
@@ -591,7 +594,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert a valid doc
|
||||
appSearchImpl.putDocument(
|
||||
@@ -626,7 +630,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert document
|
||||
GenericDocument document = new GenericDocument.Builder<>("namespace", "id", "type").build();
|
||||
@@ -660,7 +665,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
mAppSearchImpl.setSchema(
|
||||
"package",
|
||||
"database2",
|
||||
@@ -669,7 +675,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert documents
|
||||
GenericDocument document1 =
|
||||
@@ -714,7 +721,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert document
|
||||
GenericDocument document = new GenericDocument.Builder<>("namespace", "id", "type").build();
|
||||
@@ -756,7 +764,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert package2 schema
|
||||
List<AppSearchSchema> schema2 =
|
||||
@@ -769,7 +778,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert package1 document
|
||||
GenericDocument document =
|
||||
@@ -812,7 +822,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert package2 schema
|
||||
List<AppSearchSchema> schema2 =
|
||||
@@ -825,7 +836,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert package1 document
|
||||
GenericDocument document =
|
||||
@@ -889,7 +901,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert two package1 documents
|
||||
GenericDocument document1 =
|
||||
@@ -914,7 +927,8 @@ public class AppSearchImplTest {
|
||||
assertThat(searchResultPage.getResults().get(0).getGenericDocument()).isEqualTo(document2);
|
||||
|
||||
long nextPageToken = searchResultPage.getNextPageToken();
|
||||
searchResultPage = mAppSearchImpl.getNextPage("package1", nextPageToken);
|
||||
searchResultPage =
|
||||
mAppSearchImpl.getNextPage("package1", nextPageToken, /*statsBuilder=*/ null);
|
||||
assertThat(searchResultPage.getResults()).hasSize(1);
|
||||
assertThat(searchResultPage.getResults().get(0).getGenericDocument()).isEqualTo(document1);
|
||||
}
|
||||
@@ -932,7 +946,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert two package1 documents
|
||||
GenericDocument document1 =
|
||||
@@ -962,14 +977,17 @@ public class AppSearchImplTest {
|
||||
AppSearchException e =
|
||||
assertThrows(
|
||||
AppSearchException.class,
|
||||
() -> mAppSearchImpl.getNextPage("package2", nextPageToken));
|
||||
() ->
|
||||
mAppSearchImpl.getNextPage(
|
||||
"package2", nextPageToken, /*statsBuilder=*/ null));
|
||||
assertThat(e)
|
||||
.hasMessageThat()
|
||||
.contains("Package \"package2\" cannot use nextPageToken: " + nextPageToken);
|
||||
assertThat(e.getResultCode()).isEqualTo(AppSearchResult.RESULT_SECURITY_ERROR);
|
||||
|
||||
// Can continue getting next page for package1
|
||||
searchResultPage = mAppSearchImpl.getNextPage("package1", nextPageToken);
|
||||
searchResultPage =
|
||||
mAppSearchImpl.getNextPage("package1", nextPageToken, /*statsBuilder=*/ null);
|
||||
assertThat(searchResultPage.getResults()).hasSize(1);
|
||||
assertThat(searchResultPage.getResults().get(0).getGenericDocument()).isEqualTo(document1);
|
||||
}
|
||||
@@ -987,7 +1005,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert two package1 documents
|
||||
GenericDocument document1 =
|
||||
@@ -1019,7 +1038,8 @@ public class AppSearchImplTest {
|
||||
assertThat(searchResultPage.getResults().get(0).getGenericDocument()).isEqualTo(document2);
|
||||
|
||||
long nextPageToken = searchResultPage.getNextPageToken();
|
||||
searchResultPage = mAppSearchImpl.getNextPage("package1", nextPageToken);
|
||||
searchResultPage =
|
||||
mAppSearchImpl.getNextPage("package1", nextPageToken, /*statsBuilder=*/ null);
|
||||
assertThat(searchResultPage.getResults()).hasSize(1);
|
||||
assertThat(searchResultPage.getResults().get(0).getGenericDocument()).isEqualTo(document1);
|
||||
}
|
||||
@@ -1037,7 +1057,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert two package1 documents
|
||||
GenericDocument document1 =
|
||||
@@ -1074,14 +1095,17 @@ public class AppSearchImplTest {
|
||||
AppSearchException e =
|
||||
assertThrows(
|
||||
AppSearchException.class,
|
||||
() -> mAppSearchImpl.getNextPage("package2", nextPageToken));
|
||||
() ->
|
||||
mAppSearchImpl.getNextPage(
|
||||
"package2", nextPageToken, /*statsBuilder=*/ null));
|
||||
assertThat(e)
|
||||
.hasMessageThat()
|
||||
.contains("Package \"package2\" cannot use nextPageToken: " + nextPageToken);
|
||||
assertThat(e.getResultCode()).isEqualTo(AppSearchResult.RESULT_SECURITY_ERROR);
|
||||
|
||||
// Can continue getting next page for package1
|
||||
searchResultPage = mAppSearchImpl.getNextPage("package1", nextPageToken);
|
||||
searchResultPage =
|
||||
mAppSearchImpl.getNextPage("package1", nextPageToken, /*statsBuilder=*/ null);
|
||||
assertThat(searchResultPage.getResults()).hasSize(1);
|
||||
assertThat(searchResultPage.getResults().get(0).getGenericDocument()).isEqualTo(document1);
|
||||
}
|
||||
@@ -1099,7 +1123,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert two package1 documents
|
||||
GenericDocument document1 =
|
||||
@@ -1132,7 +1157,9 @@ public class AppSearchImplTest {
|
||||
AppSearchException e =
|
||||
assertThrows(
|
||||
AppSearchException.class,
|
||||
() -> mAppSearchImpl.getNextPage("package1", nextPageToken));
|
||||
() ->
|
||||
mAppSearchImpl.getNextPage(
|
||||
"package1", nextPageToken, /*statsBuilder=*/ null));
|
||||
assertThat(e)
|
||||
.hasMessageThat()
|
||||
.contains("Package \"package1\" cannot use nextPageToken: " + nextPageToken);
|
||||
@@ -1152,7 +1179,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert two package1 documents
|
||||
GenericDocument document1 =
|
||||
@@ -1189,7 +1217,8 @@ public class AppSearchImplTest {
|
||||
assertThat(e.getResultCode()).isEqualTo(AppSearchResult.RESULT_SECURITY_ERROR);
|
||||
|
||||
// Can continue getting next page for package1
|
||||
searchResultPage = mAppSearchImpl.getNextPage("package1", nextPageToken);
|
||||
searchResultPage =
|
||||
mAppSearchImpl.getNextPage("package1", nextPageToken, /*statsBuilder=*/ null);
|
||||
assertThat(searchResultPage.getResults()).hasSize(1);
|
||||
assertThat(searchResultPage.getResults().get(0).getGenericDocument()).isEqualTo(document1);
|
||||
}
|
||||
@@ -1207,7 +1236,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert two package1 documents
|
||||
GenericDocument document1 =
|
||||
@@ -1247,7 +1277,9 @@ public class AppSearchImplTest {
|
||||
AppSearchException e =
|
||||
assertThrows(
|
||||
AppSearchException.class,
|
||||
() -> mAppSearchImpl.getNextPage("package1", nextPageToken));
|
||||
() ->
|
||||
mAppSearchImpl.getNextPage(
|
||||
"package1", nextPageToken, /*statsBuilder=*/ null));
|
||||
assertThat(e)
|
||||
.hasMessageThat()
|
||||
.contains("Package \"package1\" cannot use nextPageToken: " + nextPageToken);
|
||||
@@ -1267,7 +1299,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert two package1 documents
|
||||
GenericDocument document1 =
|
||||
@@ -1311,7 +1344,8 @@ public class AppSearchImplTest {
|
||||
assertThat(e.getResultCode()).isEqualTo(AppSearchResult.RESULT_SECURITY_ERROR);
|
||||
|
||||
// Can continue getting next page for package1
|
||||
searchResultPage = mAppSearchImpl.getNextPage("package1", nextPageToken);
|
||||
searchResultPage =
|
||||
mAppSearchImpl.getNextPage("package1", nextPageToken, /*statsBuilder=*/ null);
|
||||
assertThat(searchResultPage.getResults()).hasSize(1);
|
||||
assertThat(searchResultPage.getResults().get(0).getGenericDocument()).isEqualTo(document1);
|
||||
}
|
||||
@@ -1355,7 +1389,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Create expected schemaType proto.
|
||||
SchemaProto expectedProto =
|
||||
@@ -1400,7 +1435,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Create incompatible schema
|
||||
List<AppSearchSchema> newSchemas =
|
||||
@@ -1416,7 +1452,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ true,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
assertThat(setSchemaResponse.getDeletedTypes()).containsExactly("Text");
|
||||
assertThat(setSchemaResponse.getIncompatibleTypes()).containsExactly("Email");
|
||||
}
|
||||
@@ -1439,7 +1476,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Create expected schemaType proto.
|
||||
SchemaProto expectedProto =
|
||||
@@ -1472,8 +1510,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
// Check the Document type has been deleted.
|
||||
assertThat(setSchemaResponse.getDeletedTypes()).containsExactly("Document");
|
||||
|
||||
@@ -1486,7 +1524,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ true,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Check Document schema is removed.
|
||||
expectedProto =
|
||||
@@ -1524,7 +1563,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
mAppSearchImpl.setSchema(
|
||||
"package",
|
||||
"database2",
|
||||
@@ -1533,7 +1573,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Create expected schemaType proto.
|
||||
SchemaProto expectedProto =
|
||||
@@ -1573,7 +1614,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ true,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Create expected schemaType list, database 1 should only contain Email but database 2
|
||||
// remains in same.
|
||||
@@ -1618,7 +1660,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert package document
|
||||
GenericDocument document =
|
||||
@@ -1680,7 +1723,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
mAppSearchImpl.setSchema(
|
||||
"packageB",
|
||||
"database",
|
||||
@@ -1689,7 +1733,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Verify these two packages is stored in AppSearch
|
||||
SchemaProto expectedProto =
|
||||
@@ -1735,7 +1780,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
assertThat(mAppSearchImpl.getPackageToDatabases())
|
||||
.containsExactlyEntriesIn(expectedMapping);
|
||||
|
||||
@@ -1749,7 +1795,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
assertThat(mAppSearchImpl.getPackageToDatabases())
|
||||
.containsExactlyEntriesIn(expectedMapping);
|
||||
|
||||
@@ -1763,7 +1810,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
assertThat(mAppSearchImpl.getPackageToDatabases())
|
||||
.containsExactlyEntriesIn(expectedMapping);
|
||||
}
|
||||
@@ -1822,7 +1870,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert two docs
|
||||
GenericDocument document1 =
|
||||
@@ -1973,7 +2022,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Since "package1" doesn't have a document, it get any space attributed to it.
|
||||
StorageInfo storageInfo = mAppSearchImpl.getStorageInfoForPackage("package1");
|
||||
@@ -1996,7 +2046,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert document for "package1"
|
||||
GenericDocument document =
|
||||
@@ -2012,7 +2063,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert two documents for "package2"
|
||||
document = new GenericDocument.Builder<>("namespace", "id1", "type").build();
|
||||
@@ -2061,7 +2113,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// "package2" doesn't exist yet, so it shouldn't have any storage size
|
||||
StorageInfo storageInfo =
|
||||
@@ -2084,7 +2137,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Since "package1", "database1" doesn't have a document, it get any space attributed to it.
|
||||
StorageInfo storageInfo = mAppSearchImpl.getStorageInfoForDatabase("package1", "database1");
|
||||
@@ -2106,7 +2160,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
mAppSearchImpl.setSchema(
|
||||
"package1",
|
||||
"database2",
|
||||
@@ -2115,7 +2170,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Add a document for "package1", "database1"
|
||||
GenericDocument document =
|
||||
@@ -2165,7 +2221,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
appSearchImpl.close();
|
||||
|
||||
@@ -2181,7 +2238,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0));
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null));
|
||||
|
||||
assertThrows(
|
||||
IllegalStateException.class, () -> appSearchImpl.getSchema("package", "database"));
|
||||
@@ -2225,7 +2283,9 @@ public class AppSearchImplTest {
|
||||
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> appSearchImpl.getNextPage("package", /*nextPageToken=*/ 1L));
|
||||
() ->
|
||||
appSearchImpl.getNextPage(
|
||||
"package", /*nextPageToken=*/ 1L, /*statsBuilder=*/ null));
|
||||
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
@@ -2296,7 +2356,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Add a document and persist it.
|
||||
GenericDocument document =
|
||||
@@ -2343,7 +2404,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Add two documents and persist them.
|
||||
GenericDocument document1 =
|
||||
@@ -2423,7 +2485,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Add two documents and persist them.
|
||||
GenericDocument document1 =
|
||||
@@ -2511,7 +2574,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Add two documents
|
||||
GenericDocument document1 =
|
||||
@@ -2562,7 +2626,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert a document which is too large
|
||||
GenericDocument document =
|
||||
@@ -2636,7 +2701,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Index a document
|
||||
mAppSearchImpl.putDocument(
|
||||
@@ -2723,7 +2789,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Index 3 documents
|
||||
mAppSearchImpl.putDocument(
|
||||
@@ -2836,7 +2903,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
mAppSearchImpl.setSchema(
|
||||
"package1",
|
||||
"database2",
|
||||
@@ -2845,7 +2913,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
mAppSearchImpl.setSchema(
|
||||
"package2",
|
||||
"database1",
|
||||
@@ -2854,7 +2923,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
mAppSearchImpl.setSchema(
|
||||
"package2",
|
||||
"database2",
|
||||
@@ -2863,7 +2933,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Index documents in package1/database1
|
||||
mAppSearchImpl.putDocument(
|
||||
@@ -3002,7 +3073,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Index 3 documents
|
||||
mAppSearchImpl.putDocument(
|
||||
@@ -3131,7 +3203,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Index a document
|
||||
mAppSearchImpl.putDocument(
|
||||
@@ -3210,7 +3283,8 @@ public class AppSearchImplTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Index a document
|
||||
mAppSearchImpl.putDocument(
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.android.server.appsearch.external.localstorage.stats.OptimizeStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.RemoveStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SearchStats;
|
||||
import com.android.server.appsearch.external.localstorage.stats.SetSchemaStats;
|
||||
import com.android.server.appsearch.icing.proto.DeleteStatsProto;
|
||||
import com.android.server.appsearch.icing.proto.DocumentProto;
|
||||
import com.android.server.appsearch.icing.proto.InitializeStatsProto;
|
||||
@@ -41,6 +42,7 @@ import com.android.server.appsearch.icing.proto.PutDocumentStatsProto;
|
||||
import com.android.server.appsearch.icing.proto.PutResultProto;
|
||||
import com.android.server.appsearch.icing.proto.QueryStatsProto;
|
||||
import com.android.server.appsearch.icing.proto.ScoringSpecProto;
|
||||
import com.android.server.appsearch.icing.proto.SetSchemaResultProto;
|
||||
import com.android.server.appsearch.icing.proto.StatusProto;
|
||||
import com.android.server.appsearch.icing.proto.TermMatchType;
|
||||
|
||||
@@ -57,14 +59,17 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AppSearchLoggerTest {
|
||||
@Rule public TemporaryFolder mTemporaryFolder = new TemporaryFolder();
|
||||
private AppSearchImpl mAppSearchImpl;
|
||||
private TestLogger mLogger;
|
||||
private static final String PACKAGE_NAME = "packageName";
|
||||
private static final String DATABASE = "database";
|
||||
/**
|
||||
* Always trigger optimize in this class. OptimizeStrategy will be tested in its own test class.
|
||||
*/
|
||||
private static final OptimizeStrategy ALWAYS_OPTIMIZE = optimizeInfo -> true;
|
||||
|
||||
@Rule public TemporaryFolder mTemporaryFolder = new TemporaryFolder();
|
||||
private AppSearchImpl mAppSearchImpl;
|
||||
private TestLogger mLogger;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mAppSearchImpl =
|
||||
@@ -84,6 +89,7 @@ public class AppSearchLoggerTest {
|
||||
@Nullable SearchStats mSearchStats;
|
||||
@Nullable RemoveStats mRemoveStats;
|
||||
@Nullable OptimizeStats mOptimizeStats;
|
||||
@Nullable SetSchemaStats mSetSchemaStats;
|
||||
|
||||
@Override
|
||||
public void logStats(@NonNull CallStats stats) {
|
||||
@@ -114,6 +120,11 @@ public class AppSearchLoggerTest {
|
||||
public void logStats(@NonNull OptimizeStats stats) {
|
||||
mOptimizeStats = stats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logStats(@NonNull SetSchemaStats stats) {
|
||||
mSetSchemaStats = stats;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -194,7 +205,7 @@ public class AppSearchLoggerTest {
|
||||
.setExceededMaxTokenNum(nativeExceededMaxNumTokens)
|
||||
.build())
|
||||
.build();
|
||||
PutDocumentStats.Builder pBuilder = new PutDocumentStats.Builder("packageName", "database");
|
||||
PutDocumentStats.Builder pBuilder = new PutDocumentStats.Builder(PACKAGE_NAME, DATABASE);
|
||||
|
||||
AppSearchLoggerHelper.copyNativeStats(nativePutDocumentStats, pBuilder);
|
||||
|
||||
@@ -248,8 +259,8 @@ public class AppSearchLoggerTest {
|
||||
.setDocumentRetrievalLatencyMs(nativeDocumentRetrievingLatencyMillis)
|
||||
.build();
|
||||
SearchStats.Builder qBuilder =
|
||||
new SearchStats.Builder(SearchStats.VISIBILITY_SCOPE_LOCAL, "packageName")
|
||||
.setDatabase("database");
|
||||
new SearchStats.Builder(SearchStats.VISIBILITY_SCOPE_LOCAL, PACKAGE_NAME)
|
||||
.setDatabase(DATABASE);
|
||||
|
||||
AppSearchLoggerHelper.copyNativeStats(nativeQueryStats, qBuilder);
|
||||
|
||||
@@ -336,6 +347,35 @@ public class AppSearchLoggerTest {
|
||||
.isEqualTo(nativeTimeSinceLastOptimizeMillis);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppSearchLoggerHelper_testCopyNativeStats_setSchema() {
|
||||
ImmutableList<String> newSchemaTypeChangeList = ImmutableList.of("new1");
|
||||
ImmutableList<String> deletedSchemaTypesList = ImmutableList.of("deleted1", "deleted2");
|
||||
ImmutableList<String> compatibleTypesList = ImmutableList.of("compatible1", "compatible2");
|
||||
ImmutableList<String> indexIncompatibleTypeChangeList = ImmutableList.of("index1");
|
||||
ImmutableList<String> backwardsIncompatibleTypeChangeList = ImmutableList.of("backwards1");
|
||||
SetSchemaResultProto setSchemaResultProto =
|
||||
SetSchemaResultProto.newBuilder()
|
||||
.addAllNewSchemaTypes(newSchemaTypeChangeList)
|
||||
.addAllDeletedSchemaTypes(deletedSchemaTypesList)
|
||||
.addAllFullyCompatibleChangedSchemaTypes(compatibleTypesList)
|
||||
.addAllIndexIncompatibleChangedSchemaTypes(indexIncompatibleTypeChangeList)
|
||||
.addAllIncompatibleSchemaTypes(backwardsIncompatibleTypeChangeList)
|
||||
.build();
|
||||
SetSchemaStats.Builder sBuilder = new SetSchemaStats.Builder(PACKAGE_NAME, DATABASE);
|
||||
|
||||
AppSearchLoggerHelper.copyNativeStats(setSchemaResultProto, sBuilder);
|
||||
|
||||
SetSchemaStats sStats = sBuilder.build();
|
||||
assertThat(sStats.getNewTypeCount()).isEqualTo(newSchemaTypeChangeList.size());
|
||||
assertThat(sStats.getDeletedTypeCount()).isEqualTo(deletedSchemaTypesList.size());
|
||||
assertThat(sStats.getCompatibleTypeChangeCount()).isEqualTo(compatibleTypesList.size());
|
||||
assertThat(sStats.getIndexIncompatibleTypeChangeCount())
|
||||
.isEqualTo(indexIncompatibleTypeChangeList.size());
|
||||
assertThat(sStats.getBackwardsIncompatibleTypeChangeCount())
|
||||
.isEqualTo(backwardsIncompatibleTypeChangeList.size());
|
||||
}
|
||||
|
||||
//
|
||||
// Testing actual logging
|
||||
//
|
||||
@@ -388,7 +428,8 @@ public class AppSearchLoggerTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
GenericDocument doc1 = new GenericDocument.Builder<>("namespace", "id1", "Type1").build();
|
||||
GenericDocument doc2 = new GenericDocument.Builder<>("namespace", "id2", "Type1").build();
|
||||
appSearchImpl.putDocument(testPackageName, testDatabase, doc1, mLogger);
|
||||
@@ -439,7 +480,8 @@ public class AppSearchLoggerTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// Insert a valid doc
|
||||
GenericDocument doc1 = new GenericDocument.Builder<>("namespace", "id1", "Type1").build();
|
||||
@@ -495,7 +537,8 @@ public class AppSearchLoggerTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
GenericDocument document =
|
||||
new GenericDocument.Builder<>("namespace", "id", "type")
|
||||
@@ -542,7 +585,8 @@ public class AppSearchLoggerTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
GenericDocument document =
|
||||
new GenericDocument.Builder<>("namespace", "id", "type")
|
||||
@@ -592,7 +636,8 @@ public class AppSearchLoggerTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
GenericDocument document1 =
|
||||
new GenericDocument.Builder<>("namespace", "id1", "type")
|
||||
.setPropertyString("subject", "testPut example1")
|
||||
@@ -661,7 +706,8 @@ public class AppSearchLoggerTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
SearchSpec searchSpec =
|
||||
new SearchSpec.Builder()
|
||||
@@ -701,7 +747,8 @@ public class AppSearchLoggerTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
GenericDocument document =
|
||||
new GenericDocument.Builder<>(testNamespace, testId, "type").build();
|
||||
mAppSearchImpl.putDocument(testPackageName, testDatabase, document, /*logger=*/ null);
|
||||
@@ -735,7 +782,8 @@ public class AppSearchLoggerTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
GenericDocument document =
|
||||
new GenericDocument.Builder<>(testNamespace, testId, "type").build();
|
||||
@@ -780,7 +828,8 @@ public class AppSearchLoggerTest {
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0);
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
GenericDocument document1 =
|
||||
new GenericDocument.Builder<>(testNamespace, "id1", "type").build();
|
||||
GenericDocument document2 =
|
||||
@@ -800,7 +849,58 @@ public class AppSearchLoggerTest {
|
||||
assertThat(rStats.getDatabase()).isEqualTo(testDatabase);
|
||||
assertThat(rStats.getStatusCode()).isEqualTo(AppSearchResult.RESULT_OK);
|
||||
// delete by query
|
||||
assertThat(rStats.getDeleteType()).isEqualTo(DeleteStatsProto.DeleteType.Code.QUERY_VALUE);
|
||||
assertThat(rStats.getDeleteType())
|
||||
.isEqualTo(DeleteStatsProto.DeleteType.Code.DEPRECATED_QUERY_VALUE);
|
||||
assertThat(rStats.getDeletedDocumentCount()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoggingStats_setSchema() throws Exception {
|
||||
AppSearchSchema schema1 =
|
||||
new AppSearchSchema.Builder("testSchema")
|
||||
.addProperty(
|
||||
new AppSearchSchema.StringPropertyConfig.Builder("subject")
|
||||
.setCardinality(
|
||||
AppSearchSchema.PropertyConfig.CARDINALITY_REQUIRED)
|
||||
.setIndexingType(
|
||||
AppSearchSchema.StringPropertyConfig
|
||||
.INDEXING_TYPE_PREFIXES)
|
||||
.setTokenizerType(
|
||||
AppSearchSchema.StringPropertyConfig
|
||||
.TOKENIZER_TYPE_PLAIN)
|
||||
.build())
|
||||
.build();
|
||||
mAppSearchImpl.setSchema(
|
||||
PACKAGE_NAME,
|
||||
DATABASE,
|
||||
Collections.singletonList(schema1),
|
||||
/*visibilityStore=*/ null,
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ null);
|
||||
|
||||
// create a backwards incompatible schema
|
||||
SetSchemaStats.Builder sStatsBuilder = new SetSchemaStats.Builder(PACKAGE_NAME, DATABASE);
|
||||
AppSearchSchema schema2 = new AppSearchSchema.Builder("testSchema").build();
|
||||
mAppSearchImpl.setSchema(
|
||||
PACKAGE_NAME,
|
||||
DATABASE,
|
||||
Collections.singletonList(schema2),
|
||||
/*visibilityStore=*/ null,
|
||||
/*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
|
||||
/*schemasVisibleToPackages=*/ Collections.emptyMap(),
|
||||
/*forceOverride=*/ false,
|
||||
/*version=*/ 0,
|
||||
/* setSchemaStatsBuilder= */ sStatsBuilder);
|
||||
|
||||
SetSchemaStats sStats = sStatsBuilder.build();
|
||||
assertThat(sStats.getPackageName()).isEqualTo(PACKAGE_NAME);
|
||||
assertThat(sStats.getDatabase()).isEqualTo(DATABASE);
|
||||
assertThat(sStats.getNewTypeCount()).isEqualTo(0);
|
||||
assertThat(sStats.getCompatibleTypeChangeCount()).isEqualTo(0);
|
||||
assertThat(sStats.getIndexIncompatibleTypeChangeCount()).isEqualTo(1);
|
||||
assertThat(sStats.getBackwardsIncompatibleTypeChangeCount()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,17 +264,15 @@ public class AppSearchStatsTest {
|
||||
.setMigratedDocumentCount(6)
|
||||
.setSavedDocumentCount(7)
|
||||
.build();
|
||||
int nativeLatencyMillis = 1;
|
||||
int newTypeCount = 2;
|
||||
int compatibleTypeChangeCount = 3;
|
||||
int indexIncompatibleTypeChangeCount = 4;
|
||||
int backwardsIncompatibleTypeChangeCount = 5;
|
||||
int newTypeCount = 1;
|
||||
int compatibleTypeChangeCount = 2;
|
||||
int indexIncompatibleTypeChangeCount = 3;
|
||||
int backwardsIncompatibleTypeChangeCount = 4;
|
||||
SetSchemaStats sStats =
|
||||
new SetSchemaStats.Builder(TEST_PACKAGE_NAME, TEST_DATA_BASE)
|
||||
.setStatusCode(TEST_STATUS_CODE)
|
||||
.setSchemaMigrationStats(schemaMigrationStats)
|
||||
.setTotalLatencyMillis(TEST_TOTAL_LATENCY_MILLIS)
|
||||
.setNativeLatencyMillis(nativeLatencyMillis)
|
||||
.setNewTypeCount(newTypeCount)
|
||||
.setCompatibleTypeChangeCount(compatibleTypeChangeCount)
|
||||
.setIndexIncompatibleTypeChangeCount(indexIncompatibleTypeChangeCount)
|
||||
@@ -287,7 +285,6 @@ public class AppSearchStatsTest {
|
||||
assertThat(sStats.getStatusCode()).isEqualTo(TEST_STATUS_CODE);
|
||||
assertThat(sStats.getSchemaMigrationStats()).isEqualTo(schemaMigrationStats);
|
||||
assertThat(sStats.getTotalLatencyMillis()).isEqualTo(TEST_TOTAL_LATENCY_MILLIS);
|
||||
assertThat(sStats.getNativeLatencyMillis()).isEqualTo(nativeLatencyMillis);
|
||||
assertThat(sStats.getNewTypeCount()).isEqualTo(newTypeCount);
|
||||
assertThat(sStats.getCompatibleTypeChangeCount()).isEqualTo(compatibleTypeChangeCount);
|
||||
assertThat(sStats.getIndexIncompatibleTypeChangeCount())
|
||||
|
||||
Reference in New Issue
Block a user