Skip to content

Commit

Permalink
test: fix logging tests (#493)
Browse files Browse the repository at this point in the history
* fix: inconsistent log ordering in tests
* fix: formatting fixes
  • Loading branch information
Simon Zeltser authored Apr 20, 2021
1 parent f5581a5 commit 99c9653
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* @googleapis/api-logging @googleapis/yoshi-java

# The java-samples-reviewers team is the default owner for samples changes
samples/**/*.java @googleapis/java-samples-reviewers
samples/**/*.java @googleapis/java-samples-reviewers @googleapis/api-logging
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ public LoggingHandler(

this.enhancers.addAll(enhancersParam);

// In the following line getResourceEnhancers() never returns null (@NotNull attribute)
List<LoggingEnhancer> loggingEnhancers = MonitoredResourceUtil.getResourceEnhancers();
if (loggingEnhancers != null) {
this.enhancers.addAll(loggingEnhancers);
}
this.enhancers.addAll(loggingEnhancers);
} catch (Exception ex) {
reportError(null, ex, ErrorManager.OPEN_FAILURE);
throw ex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !(obj instanceof BucketDestination)) {
if (!(obj instanceof BucketDestination)) {
return false;
}
BucketDestination other = (BucketDestination) obj;
Expand Down Expand Up @@ -171,7 +171,7 @@ public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !(obj instanceof DatasetDestination)) {
if (!(obj instanceof DatasetDestination)) {
return false;
}
DatasetDestination other = (DatasetDestination) obj;
Expand Down Expand Up @@ -270,7 +270,7 @@ public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !(obj instanceof LoggingBucketDestination)) {
if (!(obj instanceof LoggingBucketDestination)) {
return false;
}
LoggingBucketDestination other = (LoggingBucketDestination) obj;
Expand Down Expand Up @@ -363,7 +363,7 @@ public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || !(obj instanceof TopicDestination)) {
if (!(obj instanceof TopicDestination)) {
return false;
}
TopicDestination other = (TopicDestination) obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@
import static org.junit.Assert.assertTrue;

import com.google.cloud.MonitoredResource;
import com.google.cloud.logging.BaseSystemTest;
import com.google.cloud.logging.HttpRequest;
import com.google.cloud.logging.LogEntry;
import com.google.cloud.logging.Logging;
import com.google.cloud.logging.LoggingOptions;
import com.google.cloud.logging.Operation;
import com.google.cloud.logging.Payload;
import com.google.cloud.logging.Severity;
import com.google.cloud.logging.*;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.logging.v2.LogName;
Expand All @@ -58,6 +51,10 @@ public class ITLoggingTest extends BaseSystemTest {

@BeforeClass
public static void insertLogs() {
// This ensures predictability of the test:
// with batching enabled by default, it's possible that for two log entries, batching
// will send them together, so they might be stored not in the same logical order.
logging.setWriteSynchronicity(Synchronicity.SYNC);
LogEntry firstEntry =
LogEntry.newBuilder(FIRST_PAYLOAD)
.addLabel("key1", "value1")
Expand All @@ -74,7 +71,6 @@ public static void insertLogs() {
.setResource(CLOUDSQL_RESOURCE)
.build();
logging.write(ImmutableList.of(firstEntry));
logging.flush();
logging.write(ImmutableList.of(secondEntry));
logging.flush();
}
Expand Down

0 comments on commit 99c9653

Please sign in to comment.