Skip to content

Fix remaining lint failures (mostly in tests) #2025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.database;

import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
import static com.google.firebase.database.snapshot.NodeUtilities.NodeFromJSON;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -109,7 +110,7 @@ public static Node leafNodeOfSize(int size) {
}
int remainingLength = size - builder.length();
builder.append(pattern.substring(0, remainingLength));
assert builder.length() == size : "The string size did not match the expected size";
hardAssert(builder.length() == size, "The string size did not match the expected size");
return NodeFromJSON(builder.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.database.snapshot;

import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

Expand Down Expand Up @@ -81,7 +82,7 @@ private static void forEachLeaf(
} else if (node.isEmpty()) {
// ignore
} else {
assert node instanceof ChildrenNode;
hardAssert(node instanceof ChildrenNode);
((ChildrenNode) node)
.forEachChild(
new ChildrenNode.ChildVisitor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -223,7 +224,7 @@ public void saveUserOverwrite(Path path, Node node, long writeId) {
saveWrite(path, writeId, WRITE_TYPE_OVERWRITE, serializedNode);
long duration = System.currentTimeMillis() - start;
if (logger.logsDebug()) {
logger.debug(String.format("Persisted user overwrite in %dms", duration));
logger.debug(String.format(Locale.US, "Persisted user overwrite in %dms", duration));
}
}

Expand All @@ -235,7 +236,7 @@ public void saveUserMerge(Path path, CompoundWrite children, long writeId) {
saveWrite(path, writeId, WRITE_TYPE_MERGE, serializedNode);
long duration = System.currentTimeMillis() - start;
if (logger.logsDebug()) {
logger.debug(String.format("Persisted user merge in %dms", duration));
logger.debug(String.format(Locale.US, "Persisted user merge in %dms", duration));
}
}

Expand All @@ -247,7 +248,8 @@ public void removeUserWrite(long writeId) {
long duration = System.currentTimeMillis() - start;
if (logger.logsDebug()) {
logger.debug(
String.format("Deleted %d write(s) with writeId %d in %dms", count, writeId, duration));
String.format(
Locale.US, "Deleted %d write(s) with writeId %d in %dms", count, writeId, duration));
}
}

Expand Down Expand Up @@ -309,7 +311,7 @@ record = new UserWriteRecord(writeId, path, merge);
}
long duration = System.currentTimeMillis() - start;
if (logger.logsDebug()) {
logger.debug(String.format("Loaded %d writes in %dms", writes.size(), duration));
logger.debug(String.format(Locale.US, "Loaded %d writes in %dms", writes.size(), duration));
}
return writes;
} catch (IOException e) {
Expand Down Expand Up @@ -381,8 +383,12 @@ private void updateServerCache(Path path, Node node, boolean merge) {
if (logger.logsDebug()) {
logger.debug(
String.format(
Locale.US,
"Persisted a total of %d rows and deleted %d rows for a set at %s in %dms",
savedRows, removedRows, path.toString(), duration));
savedRows,
removedRows,
path.toString(),
duration));
}
}

Expand All @@ -400,8 +406,12 @@ public void mergeIntoServerCache(Path path, CompoundWrite children) {
if (logger.logsDebug()) {
logger.debug(
String.format(
Locale.US,
"Persisted a total of %d rows and deleted %d rows for a merge at %s in %dms",
savedRows, removedRows, path.toString(), duration));
savedRows,
removedRows,
path.toString(),
duration));
}
}

Expand Down Expand Up @@ -438,7 +448,7 @@ public void saveTrackedQuery(TrackedQuery trackedQuery) {
TRACKED_QUERY_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
long duration = System.currentTimeMillis() - start;
if (logger.logsDebug()) {
logger.debug(String.format("Saved new tracked query in %dms", duration));
logger.debug(String.format(Locale.US, "Saved new tracked query in %dms", duration));
}
}

Expand Down Expand Up @@ -496,7 +506,9 @@ public List<TrackedQuery> loadTrackedQueries() {
}
long duration = System.currentTimeMillis() - start;
if (logger.logsDebug()) {
logger.debug(String.format("Loaded %d tracked queries in %dms", queries.size(), duration));
logger.debug(
String.format(
Locale.US, "Loaded %d tracked queries in %dms", queries.size(), duration));
}
return queries;
} finally {
Expand All @@ -519,7 +531,7 @@ public void resetPreviouslyActiveTrackedQueries(long lastUse) {
TRACKED_QUERY_TABLE, values, whereClause, new String[] {}, SQLiteDatabase.CONFLICT_REPLACE);
long duration = System.currentTimeMillis() - start;
if (logger.logsDebug()) {
logger.debug(String.format("Reset active tracked queries in %dms", duration));
logger.debug(String.format(Locale.US, "Reset active tracked queries in %dms", duration));
}
}

Expand All @@ -544,8 +556,11 @@ public void saveTrackedQueryKeys(long trackedQueryId, Set<ChildKey> keys) {
if (logger.logsDebug()) {
logger.debug(
String.format(
Locale.US,
"Set %d tracked query keys for tracked query %d in %dms",
keys.size(), trackedQueryId, duration));
keys.size(),
trackedQueryId,
duration));
}
}

Expand All @@ -572,8 +587,12 @@ public void updateTrackedQueryKeys(
if (logger.logsDebug()) {
logger.debug(
String.format(
Locale.US,
"Updated tracked query keys (%d added, %d removed) for tracked query id %d in %dms",
added.size(), removed.size(), trackedQueryId, duration));
added.size(),
removed.size(),
trackedQueryId,
duration));
}
}

Expand Down Expand Up @@ -610,8 +629,11 @@ public Set<ChildKey> loadTrackedQueryKeys(Set<Long> trackedQueryIds) {
if (logger.logsDebug()) {
logger.debug(
String.format(
Locale.US,
"Loaded %d tracked queries keys for tracked queries %s in %dms",
keys.size(), trackedQueryIds.toString(), duration));
keys.size(),
trackedQueryIds.toString(),
duration));
}
return keys;
} finally {
Expand Down Expand Up @@ -681,7 +703,11 @@ public void pruneCache(Path root, PruneForest pruneForest) {
if (logger.logsDebug()) {
logger.debug(
String.format(
"Pruned %d rows with %d nodes resaved in %dms", prunedCount, resavedCount, duration));
Locale.US,
"Pruned %d rows with %d nodes resaved in %dms",
prunedCount,
resavedCount,
duration));
}
}

Expand Down Expand Up @@ -709,7 +735,11 @@ public Integer onNodeValue(Path keepPath, Void ignore, Integer nodesToResave) {
Path absolutePath = pruneRoot.child(relativePath);
if (logger.logsDebug()) {
logger.debug(
String.format("Need to rewrite %d nodes below path %s", nodesToResave, absolutePath));
String.format(
Locale.US,
"Need to rewrite %d nodes below path %s",
nodesToResave,
absolutePath));
}
final Node currentNode = loadNested(absolutePath);
pruneForest.foldKeptNodes(
Expand Down Expand Up @@ -750,7 +780,7 @@ public void removeAllUserWrites() {
int count = database.delete(WRITES_TABLE, null, null);
long duration = System.currentTimeMillis() - start;
if (logger.logsDebug()) {
logger.debug(String.format("Deleted %d (all) write(s) in %dms", count, duration));
logger.debug(String.format(Locale.US, "Deleted %d (all) write(s) in %dms", count, duration));
}
}

Expand Down Expand Up @@ -781,7 +811,7 @@ public void endTransaction() {
insideTransaction = false;
long elapsed = System.currentTimeMillis() - transactionStart;
if (logger.logsDebug()) {
logger.debug(String.format("Transaction completed. Elapsed: %dms", elapsed));
logger.debug(String.format(Locale.US, "Transaction completed. Elapsed: %dms", elapsed));
}
}

Expand Down Expand Up @@ -854,9 +884,12 @@ private int saveNested(Path path, Node node) {
if (logger.logsDebug()) {
logger.debug(
String.format(
Locale.US,
"Node estimated serialized size at path %s of %d bytes exceeds limit of %d bytes. "
+ "Splitting up.",
path, estimatedSize, CHILDREN_NODE_SPLIT_SIZE_THRESHOLD));
path,
estimatedSize,
CHILDREN_NODE_SPLIT_SIZE_THRESHOLD));
}
// split up the children node into multiple nodes
int sum = 0;
Expand All @@ -881,7 +914,7 @@ private int saveNested(Path path, Node node) {
}

private String partKey(Path path, int i) {
return pathToKey(path) + String.format(PART_KEY_FORMAT, i);
return pathToKey(path) + String.format(Locale.US, PART_KEY_FORMAT, i);
}

private void saveNode(Path path, Node node) {
Expand Down Expand Up @@ -984,6 +1017,7 @@ private Node loadNested(Path path) {
if (logger.logsDebug()) {
logger.debug(
String.format(
Locale.US,
"Loaded a total of %d rows for a total of %d nodes at %s in %dms "
+ "(Query: %dms, Loading: %dms, Serializing: %dms)",
payloads.size(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.google.firebase.database.core;

import static com.google.firebase.database.core.utilities.Utilities.hardAssert;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
Expand Down Expand Up @@ -66,15 +68,15 @@ public void startListening(
SyncTree.CompletionListener onListenComplete) {
Path path = query.getPath();
logger.debug("Listening at " + path + " for Tag " + tag + ")");
assert !listens.contains(query) : "Duplicate listen";
hardAssert(!listens.contains(query), "Duplicate listen");
this.listens.add(query);
}

@Override
public void stopListening(QuerySpec query, Tag tag) {
Path path = query.getPath();
logger.debug("Stop listening at " + path + " for Tag " + tag + ")");
assert this.listens.contains(query) : "Stopped listening for query already";
hardAssert(this.listens.contains(query), "Stopped listening for query already");
this.listens.remove(query);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.database.core.persistence;

import static com.google.firebase.database.core.utilities.Utilities.hardAssert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -116,7 +117,7 @@ private void applyOperation(SyncTree syncTree, Operation operation, Map<QuerySpe
if (operation.getSource().isTagged()) {
Tag tag =
tagMap.get(new QuerySpec(operation.getPath(), operation.getSource().getQueryParams()));
assert tag != null;
hardAssert(tag != null);
switch (operation.getType()) {
case ListenComplete:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.google.firebase.database.core;

import static com.google.firebase.database.core.utilities.Utilities.hardAssert;

import com.google.firebase.database.core.operation.AckUserWrite;
import com.google.firebase.database.core.operation.ListenComplete;
import com.google.firebase.database.core.operation.Merge;
Expand Down Expand Up @@ -285,7 +287,7 @@ public CacheNode getExpectedClientState(QueryParams params) {
private Operation getAck() {
WriteOp op = this.writeOpForLastUpdate;
WriteOp frontOp = outstandingWrites.remove();
assert op == frontOp : "The write op should be the front of the queue";
hardAssert(op == frontOp, "The write op should be the front of the queue");
writeTree.removeWrite(op.writeId);
this.writeOpForLastUpdate = null;
return getAckForWrite(op.operation, /*revert=*/ false);
Expand All @@ -296,7 +298,7 @@ private Operation getAckForWrite(Operation writeOp, boolean revert) {
Overwrite overwrite = (Overwrite) writeOp;
return new AckUserWrite(overwrite.getPath(), new ImmutableTree<Boolean>(true), revert);
} else {
assert (writeOp.getType() == Operation.OperationType.Merge);
hardAssert(writeOp.getType() == Operation.OperationType.Merge);
Merge merge = (Merge) writeOp;
ImmutableTree<Boolean> affectedTree = ImmutableTree.emptyInstance();
for (Map.Entry<Path, Node> entry : merge.getChildren()) {
Expand Down Expand Up @@ -465,7 +467,8 @@ private Map<ChildKey, Node> getMergeMap(Merge merge) {
merge.getChildren().childCompoundWrites().entrySet()) {
ChildKey key = entry.getKey();
CompoundWrite childWrite = entry.getValue();
assert childWrite.rootWrite() != null : "This is a deep overwrite, which is not supported";
hardAssert(
childWrite.rootWrite() != null, "This is a deep overwrite, which is not supported");
map.put(key, childWrite.rootWrite());
}
return map;
Expand All @@ -485,7 +488,7 @@ private Overwrite getRandomOverwrite(OperationSource source) {
}

private static Operation userOperationToServerOperation(Operation operation) {
assert operation.getSource().isFromUser();
hardAssert(operation.getSource().isFromUser());
switch (operation.getType()) {
case Overwrite:
{
Expand Down
Loading