From 8bf9eab077037ba5d16ab45d92aef9a5fae5c0b8 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 21 Oct 2016 12:51:16 +0200 Subject: [PATCH] Rename setters/getters/builders for Logging classes to meet proto conventions (#1313) * Rename setters/getters/builders for Logging classes to meet proto conventions * Update Logging examples, snippets and READMEs to use renamed getters/setters/builders * Make deprecated methods call renamed ones --- README.md | 6 +- TESTING.md | 2 +- .../com/google/cloud/MonitoredResource.java | 52 +++- .../cloud/MonitoredResourceDescriptor.java | 93 +++++- .../MonitoredResourceDescriptorTest.java | 63 +++- .../google/cloud/MonitoredResourceTest.java | 53 +++- .../com/google/cloud/SerializationTest.java | 8 +- .../examples/logging/LoggingExample.java | 16 +- .../snippets/CreateAndListMetrics.java | 4 +- .../logging/snippets/CreateAndListSinks.java | 4 +- .../logging/snippets/LoggingSnippets.java | 24 +- .../logging/snippets/MetricSnippets.java | 4 +- .../logging/snippets/SinkSnippets.java | 4 +- .../snippets/WriteAndListLogEntries.java | 6 +- google-cloud-logging/README.md | 10 +- .../cloud/logging/AsyncLoggingHandler.java | 2 +- .../com/google/cloud/logging/HttpRequest.java | 247 ++++++++++++++- .../com/google/cloud/logging/LogEntry.java | 202 +++++++++++- .../com/google/cloud/logging/Logging.java | 32 +- .../google/cloud/logging/LoggingHandler.java | 16 +- .../com/google/cloud/logging/LoggingImpl.java | 7 +- .../google/cloud/logging/LoggingLevel.java | 8 + .../java/com/google/cloud/logging/Metric.java | 44 ++- .../com/google/cloud/logging/MetricInfo.java | 89 +++++- .../com/google/cloud/logging/Operation.java | 74 ++++- .../java/com/google/cloud/logging/Option.java | 4 +- .../com/google/cloud/logging/Payload.java | 37 ++- .../java/com/google/cloud/logging/Sink.java | 52 +++- .../com/google/cloud/logging/SinkInfo.java | 180 ++++++++++- .../com/google/cloud/logging/Structs.java | 6 +- .../google/cloud/logging/package-info.java | 6 +- .../logging/testing/RemoteLoggingHelper.java | 12 +- .../cloud/logging/testing/package-info.java | 2 +- .../logging/AsyncLoggingHandlerTest.java | 4 +- .../google/cloud/logging/BaseSystemTest.java | 293 +++++++++--------- .../google/cloud/logging/HttpRequestTest.java | 185 ++++++----- .../google/cloud/logging/LogEntryTest.java | 269 ++++++++++------ .../cloud/logging/LoggingHandlerTest.java | 52 ++-- .../google/cloud/logging/LoggingImplTest.java | 18 +- .../cloud/logging/LoggingLevelTest.java | 6 + .../com/google/cloud/logging/LoggingTest.java | 40 +-- .../google/cloud/logging/MetricInfoTest.java | 50 ++- .../com/google/cloud/logging/MetricTest.java | 41 ++- .../google/cloud/logging/OperationTest.java | 50 ++- .../com/google/cloud/logging/OptionTest.java | 16 +- .../com/google/cloud/logging/PayloadTest.java | 19 +- .../cloud/logging/SerializationTest.java | 6 +- .../google/cloud/logging/SinkInfoTest.java | 165 +++++++--- .../com/google/cloud/logging/SinkTest.java | 44 ++- .../com/google/cloud/logging/StructsTest.java | 4 +- .../cloud/logging/it/ITLoggingTest.java | 2 +- 51 files changed, 1955 insertions(+), 678 deletions(-) diff --git a/README.md b/README.md index d85c8ab3bcf4..0230de56ae63 100644 --- a/README.md +++ b/README.md @@ -412,9 +412,9 @@ import java.util.Iterator; LoggingOptions options = LoggingOptions.defaultInstance(); try(Logging logging = options.service()) { - LogEntry firstEntry = LogEntry.builder(StringPayload.of("message")) - .logName("test-log") - .resource(MonitoredResource.builder("global") + LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message")) + .setLogName("test-log") + .setResource(MonitoredResource.builder("global") .addLabel("project_id", options.projectId()) .build()) .build(); diff --git a/TESTING.md b/TESTING.md index 606caddda375..cc7dce9f1462 100644 --- a/TESTING.md +++ b/TESTING.md @@ -164,7 +164,7 @@ uses the `RemoteLoggingHelper` to create a metric. ```java RemoteLoggingHelper loggingHelper = RemoteLoggingHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json")); - Logging logging = loggingHelper.options().service(); + Logging logging = loggingHelper.getOptions().service(); // Pick a name for the resource with low probability of clashing String metricName = RemoteLoggingHelper.formatForTest("test-metric"); MetricInfo metricInfo = MetricInfo.of(name, "logName:syslog"); diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java index 584bc80ced02..66cd15ce1eec 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResource.java @@ -66,7 +66,17 @@ public static class Builder { * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. */ + @Deprecated public Builder type(String type) { + return setType(type); + } + + /** + * Sets the monitored resource type. This value must match the one of + * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. + * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. + */ + public Builder setType(String type) { this.type = type; return this; } @@ -76,7 +86,17 @@ public Builder type(String type) { * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute * Engine VM instances use the labels {@code instance_id} and {@code zone}. */ + @Deprecated public Builder labels(Map labels) { + return setLabels(labels); + } + + /** + * Sets the values for all the labels required by the corresponding monitored resource + * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute + * Engine VM instances use the labels {@code instance_id} and {@code zone}. + */ + public Builder setLabels(Map labels) { this.labels = new HashMap<>(checkNotNull(labels)); return this; } @@ -112,7 +132,17 @@ public MonitoredResource build() { * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. */ + @Deprecated public String type() { + return getType(); + } + + /** + * Returns the monitored resource type. This value must match the one of + * {@link MonitoredResourceDescriptor#type()} of a {@code MonitoredResourceDescriptor} object. + * For example, the type {@code cloudsql_database} represent databases in Google Cloud SQL. + */ + public String getType() { return type; } @@ -121,7 +151,17 @@ public String type() { * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute * Engine VM instances use the labels {@code instance_id} and {@code zone}. */ + @Deprecated public Map labels() { + return getLabels(); + } + + /** + * Returns the values for all the labels required by the corresponding monitored resource + * descriptor (see {@link MonitoredResourceDescriptor#labels()}. For example, Google Compute + * Engine VM instances use the labels {@code instance_id} and {@code zone}. + */ + public Map getLabels() { return labels; } @@ -167,7 +207,15 @@ public Builder toBuilder() { /** * Returns a builder for {@code MonitoredResource} objects given the resource's type. */ + @Deprecated public static Builder builder(String type) { + return newBuilder(type); + } + + /** + * Returns a builder for {@code MonitoredResource} objects given the resource's type. + */ + public static Builder newBuilder(String type) { return new Builder(type); } @@ -175,10 +223,10 @@ public static Builder builder(String type) { * Creates a {@code MonitoredResource} object given the resource's type and labels. */ public static MonitoredResource of(String type, Map labels) { - return builder(type).labels(labels).build(); + return newBuilder(type).setLabels(labels).build(); } public static MonitoredResource fromPb(com.google.api.MonitoredResource descriptorPb) { - return new Builder(descriptorPb.getType()).labels(descriptorPb.getLabels()).build(); + return new Builder(descriptorPb.getType()).setLabels(descriptorPb.getLabelsMap()).build(); } } diff --git a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java index cb121094ef31..ebee6544df4a 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java +++ b/google-cloud-core/src/main/java/com/google/cloud/MonitoredResourceDescriptor.java @@ -120,14 +120,30 @@ static ValueType fromPb(com.google.api.LabelDescriptor.ValueType typePb) { /** * Returns the key associated to this label. */ + @Deprecated public String key() { + return getKey(); + } + + /** + * Returns the key associated to this label. + */ + public String getKey() { return key; } /** * Returns the type of data that can be assigned to this label. */ + @Deprecated public ValueType valueType() { + return getValueType(); + } + + /** + * Returns the type of data that can be assigned to this label. + */ + public ValueType getValueType() { return valueType; } @@ -135,7 +151,16 @@ public ValueType valueType() { * Returns the optional human-readable description for this label. If not set, this method * returns {@code null}. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns the optional human-readable description for this label. If not set, this method + * returns {@code null}. + */ + public String getDescription() { return description; } @@ -199,22 +224,22 @@ static class Builder { this.type = type; } - Builder name(String name) { + Builder setName(String name) { this.name = name; return this; } - Builder displayName(String displayName) { + Builder setDisplayName(String displayName) { this.displayName = displayName; return this; } - Builder description(String description) { + Builder setDescription(String description) { this.description = description; return this; } - Builder labels(List labels) { + Builder setLabels(List labels) { this.labels = labels; return this; } @@ -236,7 +261,16 @@ MonitoredResourceDescriptor build() { * Returns the monitored resource type. For example, the type {@code cloudsql_database} represents * databases in Google Cloud SQL. */ + @Deprecated public String type() { + return getType(); + } + + /** + * Returns the monitored resource type. For example, the type {@code cloudsql_database} represents + * databases in Google Cloud SQL. + */ + public String getType() { return type; } @@ -244,7 +278,16 @@ public String type() { * Returns an optional name for the monitored resource descriptor. If not set, this method returns * {@code null}. */ + @Deprecated public String name() { + return getName(); + } + + /** + * Returns an optional name for the monitored resource descriptor. If not set, this method returns + * {@code null}. + */ + public String getName() { return name; } @@ -253,7 +296,17 @@ public String name() { * in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method * returns {@code null}. */ + @Deprecated public String displayName() { + return getDisplayName(); + } + + /** + * Returns an optional concise name for the monitored resource type. This value might be displayed + * in user interfaces. For example, {@code Google Cloud SQL Database}. If not set, this method + * returns {@code null}. + */ + public String getDisplayName() { return displayName; } @@ -261,7 +314,16 @@ public String displayName() { * Returns an optional detailed description of the monitored resource type. This value might be * used in documentation. If not set, this method returns {@code null}. */ + @Deprecated public String description() { + return getDescription(); + } + + /** + * Returns an optional detailed description of the monitored resource type. This value might be + * used in documentation. If not set, this method returns {@code null}. + */ + public String getDescription() { return description; } @@ -270,7 +332,17 @@ public String description() { * example, an individual Google Cloud SQL database is identified by values for the labels * {@code database_id} and {@code region}. */ + @Deprecated public List labels() { + return getLabels(); + } + + /** + * Returns a list of labels used to describe instances of this monitored resource type. For + * example, an individual Google Cloud SQL database is identified by values for the labels + * {@code database_id} and {@code region}. + */ + public List getLabels() { return labels; } @@ -323,23 +395,24 @@ public com.google.api.MonitoredResourceDescriptor toPb() { return builder.build(); } - static Builder builder(String type) { + static Builder newBuilder(String type) { return new Builder(type); } public static MonitoredResourceDescriptor fromPb( com.google.api.MonitoredResourceDescriptor descriptorPb) { - Builder builder = builder(descriptorPb.getType()); + Builder builder = newBuilder(descriptorPb.getType()); if (descriptorPb.getName() != null && !descriptorPb.getName().equals("")) { - builder.name(descriptorPb.getName()); + builder.setName(descriptorPb.getName()); } if (descriptorPb.getDisplayName() != null && !descriptorPb.getDisplayName().equals("")) { - builder.displayName(descriptorPb.getDisplayName()); + builder.setDisplayName(descriptorPb.getDisplayName()); } if (descriptorPb.getDescription() != null && !descriptorPb.getDescription().equals("")) { - builder.description(descriptorPb.getDescription()); + builder.setDescription(descriptorPb.getDescription()); } - builder.labels(Lists.transform(descriptorPb.getLabelsList(), LabelDescriptor.FROM_PB_FUNCTION)); + builder.setLabels(Lists.transform(descriptorPb.getLabelsList(), + LabelDescriptor.FROM_PB_FUNCTION)); return builder.build(); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java index cab0438e05d8..24a8be62e760 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceDescriptorTest.java @@ -44,15 +44,31 @@ public class MonitoredResourceDescriptorTest { private static final List LABELS = ImmutableList.of(BOOLEAN_LABEL, STRING_LABEL, INT_LABEL); private static final MonitoredResourceDescriptor RESOURCE_DESCRIPTOR = - MonitoredResourceDescriptor.builder(TYPE) - .name(NAME) - .displayName(DISPLAY_NAME) - .description(DESCRIPTION) - .labels(LABELS) + MonitoredResourceDescriptor.newBuilder(TYPE) + .setName(NAME) + .setDisplayName(DISPLAY_NAME) + .setDescription(DESCRIPTION) + .setLabels(LABELS) .build(); @Test public void testLabelDescriptor() { + assertEquals("booleanKey", BOOLEAN_LABEL.getKey()); + assertEquals(ValueType.BOOL, BOOLEAN_LABEL.getValueType()); + assertEquals("Boolean label", BOOLEAN_LABEL.getDescription()); + assertEquals("stringKey", STRING_LABEL.getKey()); + assertEquals(ValueType.STRING, STRING_LABEL.getValueType()); + assertEquals("String label", STRING_LABEL.getDescription()); + assertEquals("intKey", INT_LABEL.getKey()); + assertEquals(ValueType.INT64, INT_LABEL.getValueType()); + assertEquals("Int label", INT_LABEL.getDescription()); + assertEquals("intKey", INT_LABEL_NO_DESCRIPTION.getKey()); + assertEquals(ValueType.INT64, INT_LABEL_NO_DESCRIPTION.getValueType()); + assertNull(INT_LABEL_NO_DESCRIPTION.getDescription()); + } + + @Test + public void testLabelDescriptorDeprecated() { assertEquals("booleanKey", BOOLEAN_LABEL.key()); assertEquals(ValueType.BOOL, BOOLEAN_LABEL.valueType()); assertEquals("Boolean label", BOOLEAN_LABEL.description()); @@ -69,13 +85,29 @@ public void testLabelDescriptor() { @Test public void testBuilder() { + assertEquals(TYPE, RESOURCE_DESCRIPTOR.getType()); + assertEquals(NAME, RESOURCE_DESCRIPTOR.getName()); + assertEquals(DISPLAY_NAME, RESOURCE_DESCRIPTOR.getDisplayName()); + assertEquals(DESCRIPTION, RESOURCE_DESCRIPTOR.getDescription()); + assertEquals(LABELS, RESOURCE_DESCRIPTOR.getLabels()); + MonitoredResourceDescriptor resourceDescriptor = + MonitoredResourceDescriptor.newBuilder(TYPE).build(); + assertEquals(TYPE, resourceDescriptor.getType()); + assertNull(resourceDescriptor.getName()); + assertNull(resourceDescriptor.getDisplayName()); + assertNull(resourceDescriptor.getDescription()); + assertEquals(ImmutableList.of(), resourceDescriptor.getLabels()); + } + + @Test + public void testBuilderDeprecated() { assertEquals(TYPE, RESOURCE_DESCRIPTOR.type()); assertEquals(NAME, RESOURCE_DESCRIPTOR.name()); assertEquals(DISPLAY_NAME, RESOURCE_DESCRIPTOR.displayName()); assertEquals(DESCRIPTION, RESOURCE_DESCRIPTOR.description()); assertEquals(LABELS, RESOURCE_DESCRIPTOR.labels()); MonitoredResourceDescriptor resourceDescriptor = - MonitoredResourceDescriptor.builder(TYPE).build(); + MonitoredResourceDescriptor.newBuilder(TYPE).build(); assertEquals(TYPE, resourceDescriptor.type()); assertNull(resourceDescriptor.name()); assertNull(resourceDescriptor.displayName()); @@ -83,7 +115,6 @@ public void testBuilder() { assertEquals(ImmutableList.of(), resourceDescriptor.labels()); } - @Test public void testToAndFromPbLabelDescriptor() { compareLabelDescriptor(BOOLEAN_LABEL, LabelDescriptor.fromPb(BOOLEAN_LABEL.toPb())); @@ -98,16 +129,16 @@ public void testToAndFromPb() { compareResourceDescriptor(RESOURCE_DESCRIPTOR, MonitoredResourceDescriptor.fromPb(RESOURCE_DESCRIPTOR.toPb())); MonitoredResourceDescriptor resourceDescriptor = - MonitoredResourceDescriptor.builder(TYPE).build(); + MonitoredResourceDescriptor.newBuilder(TYPE).build(); compareResourceDescriptor(resourceDescriptor, MonitoredResourceDescriptor.fromPb(resourceDescriptor.toPb())); } private void compareLabelDescriptor(LabelDescriptor expected, LabelDescriptor value) { assertEquals(expected, value); - assertEquals(expected.key(), value.key()); - assertEquals(expected.valueType(), value.valueType()); - assertEquals(expected.description(), value.description()); + assertEquals(expected.getKey(), value.getKey()); + assertEquals(expected.getValueType(), value.getValueType()); + assertEquals(expected.getDescription(), value.getDescription()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } @@ -115,11 +146,11 @@ private void compareLabelDescriptor(LabelDescriptor expected, LabelDescriptor va private void compareResourceDescriptor(MonitoredResourceDescriptor expected, MonitoredResourceDescriptor value) { assertEquals(expected, value); - assertEquals(expected.type(), value.type()); - assertEquals(expected.name(), value.name()); - assertEquals(expected.displayName(), value.displayName()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.labels(), value.labels()); + assertEquals(expected.getType(), value.getType()); + assertEquals(expected.getName(), value.getName()); + assertEquals(expected.getDisplayName(), value.getDisplayName()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getLabels(), value.getLabels()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java index b42dc0c0f61b..845ff035c679 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/MonitoredResourceTest.java @@ -29,21 +29,46 @@ public class MonitoredResourceTest { private static final String TYPE = "cloudsql_database"; private static final Map LABELS = ImmutableMap.of("dataset-id", "myDataset", "zone", "myZone"); - private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.builder(TYPE) - .labels(LABELS) + private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.newBuilder(TYPE) + .setLabels(LABELS) .build(); + private static final MonitoredResource DEPRECATED_MONITORED_RESOURCE = + MonitoredResource.builder(TYPE) + .labels(LABELS) + .build(); @Test public void testBuilder() { - assertEquals(TYPE, MONITORED_RESOURCE.type()); - assertEquals(LABELS, MONITORED_RESOURCE.labels()); + assertEquals(TYPE, MONITORED_RESOURCE.getType()); + assertEquals(LABELS, MONITORED_RESOURCE.getLabels()); + MonitoredResource monitoredResource = MonitoredResource.newBuilder(TYPE) + .addLabel("dataset-id", "myDataset") + .addLabel("zone", "myZone") + .build(); + assertEquals(TYPE, monitoredResource.getType()); + assertEquals(LABELS, monitoredResource.getLabels()); + compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); + monitoredResource = MonitoredResource.newBuilder(TYPE) + .setType("global") + .addLabel("dataset-id", "myDataset") + .addLabel("zone", "myZone") + .clearLabels() + .build(); + assertEquals("global", monitoredResource.getType()); + assertEquals(ImmutableMap.of(), monitoredResource.getLabels()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(TYPE, DEPRECATED_MONITORED_RESOURCE.type()); + assertEquals(LABELS, DEPRECATED_MONITORED_RESOURCE.labels()); MonitoredResource monitoredResource = MonitoredResource.builder(TYPE) .addLabel("dataset-id", "myDataset") .addLabel("zone", "myZone") .build(); assertEquals(TYPE, monitoredResource.type()); assertEquals(LABELS, monitoredResource.labels()); - compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); + compareMonitoredResource(DEPRECATED_MONITORED_RESOURCE, monitoredResource); monitoredResource = MonitoredResource.builder(TYPE) .type("global") .addLabel("dataset-id", "myDataset") @@ -58,14 +83,14 @@ public void testBuilder() { public void testToBuilder() { compareMonitoredResource(MONITORED_RESOURCE, MONITORED_RESOURCE.toBuilder().build()); MonitoredResource monitoredResource = MONITORED_RESOURCE.toBuilder() - .type("global") + .setType("global") .clearLabels() .build(); - assertEquals("global", monitoredResource.type()); - assertEquals(ImmutableMap.of(), monitoredResource.labels()); + assertEquals("global", monitoredResource.getType()); + assertEquals(ImmutableMap.of(), monitoredResource.getLabels()); monitoredResource = monitoredResource.toBuilder() - .type(TYPE) - .labels(ImmutableMap.of("dataset-id", "myDataset")) + .setType(TYPE) + .setLabels(ImmutableMap.of("dataset-id", "myDataset")) .addLabel("zone", "myZone") .build(); compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); @@ -74,8 +99,8 @@ public void testToBuilder() { @Test public void testOf() { MonitoredResource monitoredResource = MonitoredResource.of(TYPE, LABELS); - assertEquals(TYPE, monitoredResource.type()); - assertEquals(LABELS, monitoredResource.labels()); + assertEquals(TYPE, monitoredResource.getType()); + assertEquals(LABELS, monitoredResource.getLabels()); compareMonitoredResource(MONITORED_RESOURCE, monitoredResource); } @@ -90,8 +115,8 @@ public void testToAndFromPb() { private void compareMonitoredResource(MonitoredResource expected, MonitoredResource value) { assertEquals(expected, value); - assertEquals(expected.type(), value.type()); - assertEquals(expected.labels(), value.labels()); + assertEquals(expected.getType(), value.getType()); + assertEquals(expected.getLabels(), value.getLabels()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java index 13baed858bdb..ba3194c20371 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java @@ -46,11 +46,11 @@ public class SerializationTest extends BaseSerializationTest { private static final LabelDescriptor LABEL_DESCRIPTOR = new LabelDescriptor("project_id", ValueType.STRING, "The project id"); private static final MonitoredResourceDescriptor MONITORED_RESOURCE_DESCRIPTOR = - MonitoredResourceDescriptor.builder("global") - .labels(ImmutableList.of(LABEL_DESCRIPTOR)) + MonitoredResourceDescriptor.newBuilder("global") + .setLabels(ImmutableList.of(LABEL_DESCRIPTOR)) .build(); - private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.builder("global") - .labels(ImmutableMap.of("project_id", "project")) + private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.newBuilder("global") + .setLabels(ImmutableMap.of("project_id", "project")) .build(); private static final String JSON_KEY = "{\n" + " \"private_key_id\": \"somekeyid\",\n" diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/LoggingExample.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/LoggingExample.java index f41535bc8afa..3cab8c4dd3de 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/LoggingExample.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/LoggingExample.java @@ -353,9 +353,9 @@ SinkInfo parse(String... args) throws Exception { default: throw new IllegalArgumentException("Second argument must be bucket|dataset|topic."); } - SinkInfo.Builder builder = SinkInfo.builder(name, destination); + SinkInfo.Builder builder = SinkInfo.newBuilder(name, destination); if (args.length == 4) { - builder.filter(args[3]); + builder.setFilter(args[3]); } return builder.build(); } @@ -395,10 +395,10 @@ private static class WriteEntryAction extends LoggingAction { @Override public void run(Logging logging, LogEntry entry) { - MonitoredResource resource = MonitoredResource.builder("global") + MonitoredResource resource = MonitoredResource.newBuilder("global") .addLabel("project_id", logging.options().projectId()) .build(); - LogEntry entryWithResource = entry.toBuilder().resource(resource).build(); + LogEntry entryWithResource = entry.toBuilder().setResource(resource).build(); logging.write(Collections.singleton(entryWithResource)); System.out.printf("Written entry %s%n", entryWithResource); } @@ -416,10 +416,10 @@ LogEntry parse(String... args) throws Exception { for (int i = 3; i < args.length; i += 2) { labels.put(args[i], args[i + 1]); } - return LogEntry.builder(StringPayload.of(message)) - .logName(logName) - .severity(severity) - .labels(labels) + return LogEntry.newBuilder(StringPayload.of(message)) + .setLogName(logName) + .setSeverity(severity) + .setLabels(labels) .build(); } else { throw new IllegalArgumentException("Missing required arguments."); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListMetrics.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListMetrics.java index b32e50725db0..151b5428910b 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListMetrics.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListMetrics.java @@ -39,8 +39,8 @@ public static void main(String... args) throws Exception { try(Logging logging = LoggingOptions.defaultInstance().service()) { // Create a metric - MetricInfo metricInfo = MetricInfo.builder("test-metric", "severity >= ERROR") - .description("Log entries with severity higher or equal to ERROR") + MetricInfo metricInfo = MetricInfo.newBuilder("test-metric", "severity >= ERROR") + .setDescription("Log entries with severity higher or equal to ERROR") .build(); logging.create(metricInfo); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListSinks.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListSinks.java index 2a2f7008c480..cb5b378bd7b5 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListSinks.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListSinks.java @@ -39,8 +39,8 @@ public static void main(String... args) throws Exception { try(Logging logging = LoggingOptions.defaultInstance().service()) { // Create a sink to back log entries to a BigQuery dataset - SinkInfo sinkInfo = SinkInfo.builder("test-sink", DatasetDestination.of("test-dataset")) - .filter("severity >= ERROR") + SinkInfo sinkInfo = SinkInfo.newBuilder("test-sink", DatasetDestination.of("test-dataset")) + .setFilter("severity >= ERROR") .build(); logging.create(sinkInfo); diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/LoggingSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/LoggingSnippets.java index 23e32bce2ca7..a4db3bb185fa 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/LoggingSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/LoggingSnippets.java @@ -97,9 +97,9 @@ public Sink createSinkAsync(String sinkName, String datasetName) // [VARIABLE "my_dataset"] public Sink updateSink(String sinkName, String datasetName) { // [START updateSink] - SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName)) - .versionFormat(SinkInfo.VersionFormat.V2) - .filter("severity>=ERROR") + SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)) + .setVersionFormat(SinkInfo.VersionFormat.V2) + .setFilter("severity>=ERROR") .build(); Sink sink = logging.update(sinkInfo); // [END updateSink] @@ -115,9 +115,9 @@ public Sink updateSink(String sinkName, String datasetName) { public Sink updateSinkAsync(String sinkName, String datasetName) throws ExecutionException, InterruptedException { // [START updateSinkAsync] - SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName)) - .versionFormat(SinkInfo.VersionFormat.V2) - .filter("severity>=ERROR") + SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)) + .setVersionFormat(SinkInfo.VersionFormat.V2) + .setFilter("severity>=ERROR") .build(); Future future = logging.updateAsync(sinkInfo); // ... @@ -337,8 +337,8 @@ public Metric createMetricAsync(String metricName) // [VARIABLE "my_metric_name"] public Metric updateMetric(String metricName) { // [START updateMetric] - MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR") - .description("new description") + MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR") + .setDescription("new description") .build(); Metric metric = logging.update(metricInfo); // [END updateMetric] @@ -353,8 +353,8 @@ public Metric updateMetric(String metricName) { public Metric updateMetricAsync(String metricName) throws ExecutionException, InterruptedException { // [START updateMetricAsync] - MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR") - .description("new description") + MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR") + .setDescription("new description") .build(); Future future = logging.updateAsync(metricInfo); // ... @@ -480,7 +480,7 @@ public void write(String logName) { entries.add(LogEntry.of(JsonPayload.of(jsonMap))); logging.write(entries, WriteOption.logName(logName), - WriteOption.resource(MonitoredResource.builder("global").build())); + WriteOption.resource(MonitoredResource.newBuilder("global").build())); // [END write] } @@ -500,7 +500,7 @@ public Future writeAsync(String logName) { Future future = logging.writeAsync( entries, WriteOption.logName(logName), - WriteOption.resource(MonitoredResource.builder("global").build())); + WriteOption.resource(MonitoredResource.newBuilder("global").build())); // [END writeAsync] return future; } diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/MetricSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/MetricSnippets.java index 48c6193c16fb..b986d5206e04 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/MetricSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/MetricSnippets.java @@ -75,7 +75,7 @@ public Metric reloadAsync() throws ExecutionException, InterruptedException { public Metric update() { // [START update] Metric updatedMetric = metric.toBuilder() - .description("A more detailed description") + .setDescription("A more detailed description") .build() .update(); // [END update] @@ -89,7 +89,7 @@ public Metric update() { public Metric updateAsync() throws ExecutionException, InterruptedException { // [START updateAsync] Future future = metric.toBuilder() - .description("A more detailed description") + .setDescription("A more detailed description") .build() .updateAsync(); // ... diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/SinkSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/SinkSnippets.java index 4383d07b4f62..d3896dd5f8f3 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/SinkSnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/SinkSnippets.java @@ -75,7 +75,7 @@ public Sink reloadAsync() throws ExecutionException, InterruptedException { public Sink update() { // [START update] Sink updatedSink = sink.toBuilder() - .filter("severity<=ERROR") + .setFilter("severity<=ERROR") .build() .update(); // [END update] @@ -89,7 +89,7 @@ public Sink update() { public Sink updateAsync() throws ExecutionException, InterruptedException { // [START updateAsync] Future future = sink.toBuilder() - .filter("severity<=ERROR") + .setFilter("severity<=ERROR") .build() .updateAsync(); // ... diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java index 69785430891a..cc0b8fe175c8 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java @@ -42,9 +42,9 @@ public static void main(String... args) throws Exception { try(Logging logging = options.service()) { // Create a log entry - LogEntry firstEntry = LogEntry.builder(StringPayload.of("message")) - .logName("test-log") - .resource(MonitoredResource.builder("global") + LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message")) + .setLogName("test-log") + .setResource(MonitoredResource.newBuilder("global") .addLabel("project_id", options.projectId()) .build()) .build(); diff --git a/google-cloud-logging/README.md b/google-cloud-logging/README.md index adb28e74160a..90e302dc5157 100644 --- a/google-cloud-logging/README.md +++ b/google-cloud-logging/README.md @@ -112,8 +112,8 @@ import com.google.cloud.logging.MetricInfo; Then, to create the metric, use the following code: ```java -MetricInfo metricInfo = MetricInfo.builder("test-metric", "severity >= ERROR") - .description("Log entries with severity higher or equal to ERROR") +MetricInfo metricInfo = MetricInfo.newBuilder("test-metric", "severity >= ERROR") + .setDescription("Log entries with severity higher or equal to ERROR") .build(); logging.create(metricInfo); ``` @@ -131,9 +131,9 @@ import java.util.Collections; ``` Then, to write the log entries, use the following code: ```java -LogEntry firstEntry = LogEntry.builder(StringPayload.of("message")) - .logName("test-log") - .resource(MonitoredResource.builder("global") +LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message")) + .setLogName("test-log") + .setResource(MonitoredResource.builder("global") .addLabel("project_id", options.projectId()) .build()) .build(); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/AsyncLoggingHandler.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/AsyncLoggingHandler.java index 80dd58872e0e..27ff47b1bd69 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/AsyncLoggingHandler.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/AsyncLoggingHandler.java @@ -96,6 +96,6 @@ public AsyncLoggingHandler(String logName, LoggingOptions options, MonitoredReso @Override void write(List entries, WriteOption... options) { - logging().writeAsync(entries, options); + getLogging().writeAsync(entries, options); } } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/HttpRequest.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/HttpRequest.java index ebe14032933d..efac2760d895 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/HttpRequest.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/HttpRequest.java @@ -97,7 +97,15 @@ public static final class Builder { /** * Sets the HTTP request method. */ + @Deprecated public Builder requestMethod(RequestMethod requestMethod) { + return setRequestMethod(requestMethod); + } + + /** + * Sets the HTTP request method. + */ + public Builder setRequestMethod(RequestMethod requestMethod) { this.requestMethod = requestMethod; return this; } @@ -107,7 +115,17 @@ public Builder requestMethod(RequestMethod requestMethod) { * host name, the path and the query portion of the URL that was requested. Example: * {@code http://example.com/some/info?color=red}. */ + @Deprecated public Builder requestUrl(String requestUrl) { + return setRequestUrl(requestUrl); + } + + /** + * Sets the requested URL. Request URL contains the scheme ({@code http}, {@code https}), the + * host name, the path and the query portion of the URL that was requested. Example: + * {@code http://example.com/some/info?color=red}. + */ + public Builder setRequestUrl(String requestUrl) { this.requestUrl = requestUrl; return this; } @@ -116,7 +134,16 @@ public Builder requestUrl(String requestUrl) { * Sets the size of the HTTP request message in bytes, including the request headers and the * request body. */ + @Deprecated public Builder requestSize(long requestSize) { + return setRequestSize(requestSize); + } + + /** + * Sets the size of the HTTP request message in bytes, including the request headers and the + * request body. + */ + public Builder setRequestSize(long requestSize) { this.requestSize = requestSize; return this; } @@ -124,7 +151,15 @@ public Builder requestSize(long requestSize) { /** * Sets the response code indicating the status of response. */ + @Deprecated public Builder status(int status) { + return setStatus(status); + } + + /** + * Sets the response code indicating the status of response. + */ + public Builder setStatus(int status) { this.status = status; return this; } @@ -133,7 +168,16 @@ public Builder status(int status) { * Sets the size of the HTTP response message sent back to the client, in bytes, including the * response headers and the response body. */ + @Deprecated public Builder responseSize(long responseSize) { + return setResponseSize(responseSize); + } + + /** + * Sets the size of the HTTP response message sent back to the client, in bytes, including the + * response headers and the response body. + */ + public Builder setResponseSize(long responseSize) { this.responseSize = responseSize; return this; } @@ -142,7 +186,16 @@ public Builder responseSize(long responseSize) { * Sets the user agent sent by the client. Example: * {@code Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET CLR 1.0.3705)}. */ + @Deprecated public Builder userAgent(String userAgent) { + return setUserAgent(userAgent); + } + + /** + * Sets the user agent sent by the client. Example: + * {@code Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET CLR 1.0.3705)}. + */ + public Builder setUserAgent(String userAgent) { this.userAgent = userAgent; return this; } @@ -151,7 +204,16 @@ public Builder userAgent(String userAgent) { * Sets the IP address (IPv4 or IPv6) of the client that issued the HTTP request. Examples: * {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}. */ + @Deprecated public Builder remoteIp(String remoteIp) { + return setRemoteIp(remoteIp); + } + + /** + * Sets the IP address (IPv4 or IPv6) of the client that issued the HTTP request. Examples: + * {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}. + */ + public Builder setRemoteIp(String remoteIp) { this.remoteIp = remoteIp; return this; } @@ -160,7 +222,16 @@ public Builder remoteIp(String remoteIp) { * Sets the IP address (IPv4 or IPv6) of the origin server that the request was sent to. * Examples: {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}. */ + @Deprecated public Builder serverIp(String serverIp) { + return setServerIp(serverIp); + } + + /** + * Sets the IP address (IPv4 or IPv6) of the origin server that the request was sent to. + * Examples: {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}. + */ + public Builder setServerIp(String serverIp) { this.serverIp = serverIp; return this; } @@ -171,7 +242,18 @@ public Builder serverIp(String serverIp) { * @see HTTP/1.1 Header Field * Definitions */ + @Deprecated public Builder referer(String referer) { + return setReferer(referer); + } + + /** + * Sets the referer URL of the request, as defined in HTTP/1.1 Header Field Definitions. + * + * @see HTTP/1.1 Header Field + * Definitions + */ + public Builder setReferer(String referer) { this.referer = referer; return this; } @@ -179,7 +261,15 @@ public Builder referer(String referer) { /** * Sets whether or not a cache lookup was attempted. If not set, {@code false} is used. */ + @Deprecated public Builder cacheLookup(boolean cacheLookup) { + return setCacheLookup(cacheLookup); + } + + /** + * Sets whether or not a cache lookup was attempted. If not set, {@code false} is used. + */ + public Builder setCacheLookup(boolean cacheLookup) { this.cacheLookup = cacheLookup; return this; } @@ -188,7 +278,16 @@ public Builder cacheLookup(boolean cacheLookup) { * Sets whether or not an entity was served from cache (with or without validation). If not set, * {@code false} is used. */ + @Deprecated public Builder cacheHit(boolean cacheHit) { + return setCacheHit(cacheHit); + } + + /** + * Sets whether or not an entity was served from cache (with or without validation). If not set, + * {@code false} is used. + */ + public Builder setCacheHit(boolean cacheHit) { this.cacheHit = cacheHit; return this; } @@ -198,7 +297,17 @@ public Builder cacheHit(boolean cacheHit) { * from cache. This field is only meaningful if {@link #cacheHit(boolean)} is set to * {@code true}. If not set, {@code false} is used. */ + @Deprecated public Builder cacheValidatedWithOriginServer(boolean cacheValidatedWithOriginServer) { + return setCacheValidatedWithOriginServer(cacheValidatedWithOriginServer); + } + + /** + * Sets whether or not the response was validated with the origin server before being served + * from cache. This field is only meaningful if {@link #cacheHit(boolean)} is set to + * {@code true}. If not set, {@code false} is used. + */ + public Builder setCacheValidatedWithOriginServer(boolean cacheValidatedWithOriginServer) { this.cacheValidatedWithOriginServer = cacheValidatedWithOriginServer; return this; } @@ -207,7 +316,16 @@ public Builder cacheValidatedWithOriginServer(boolean cacheValidatedWithOriginSe * Sets the number of HTTP response bytes inserted into cache. Set only when a cache fill was * attempted. */ + @Deprecated public Builder cacheFillBytes(long cacheFillBytes) { + return setCacheFillBytes(cacheFillBytes); + } + + /** + * Sets the number of HTTP response bytes inserted into cache. Set only when a cache fill was + * attempted. + */ + public Builder setCacheFillBytes(long cacheFillBytes) { this.cacheFillBytes = cacheFillBytes; return this; } @@ -239,7 +357,15 @@ public HttpRequest build() { /** * Returns the HTTP request method. */ + @Deprecated public RequestMethod requestMethod() { + return getRequestMethod(); + } + + /** + * Returns the HTTP request method. + */ + public RequestMethod getRequestMethod() { return requestMethod; } @@ -248,7 +374,17 @@ public RequestMethod requestMethod() { * host name, the path and the query portion of the URL that was requested. Example: * {@code http://example.com/some/info?color=red}. */ + @Deprecated public String requestUrl() { + return getRequestUrl(); + } + + /** + * Returns the requested URL. Request URL contains the scheme ({@code http}, {@code https}), the + * host name, the path and the query portion of the URL that was requested. Example: + * {@code http://example.com/some/info?color=red}. + */ + public String getRequestUrl() { return requestUrl; } @@ -256,14 +392,31 @@ public String requestUrl() { * Returns the size of the HTTP request message in bytes, including the request headers and the * request body. */ + @Deprecated public Long requestSize() { + return getRequestSize(); + } + + /** + * Returns the size of the HTTP request message in bytes, including the request headers and the + * request body. + */ + public Long getRequestSize() { return requestSize; } /** * Returns the response code indicating the status of response. */ + @Deprecated public Integer status() { + return getStatus(); + } + + /** + * Returns the response code indicating the status of response. + */ + public Integer getStatus() { return status; } @@ -271,7 +424,16 @@ public Integer status() { * Returns the size of the HTTP response message sent back to the client, in bytes, including the * response headers and the response body. */ + @Deprecated public Long responseSize() { + return getResponseSize(); + } + + /** + * Returns the size of the HTTP response message sent back to the client, in bytes, including the + * response headers and the response body. + */ + public Long getResponseSize() { return responseSize; } @@ -279,7 +441,16 @@ public Long responseSize() { * Returns the user agent sent by the client. Example: * {@code Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET CLR 1.0.3705)}. */ + @Deprecated public String userAgent() { + return getUserAgent(); + } + + /** + * Returns the user agent sent by the client. Example: + * {@code Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET CLR 1.0.3705)}. + */ + public String getUserAgent() { return userAgent; } @@ -287,7 +458,16 @@ public String userAgent() { * Returns the IP address (IPv4 or IPv6) of the client that issued the HTTP request. Examples: * {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}. */ + @Deprecated public String remoteIp() { + return getRemoteIp(); + } + + /** + * Returns the IP address (IPv4 or IPv6) of the client that issued the HTTP request. Examples: + * {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}. + */ + public String getRemoteIp() { return remoteIp; } @@ -295,7 +475,16 @@ public String remoteIp() { * Returns the IP address (IPv4 or IPv6) of the origin server that the request was sent to. * Examples: {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}. */ + @Deprecated public String serverIp() { + return getServerIp(); + } + + /** + * Returns the IP address (IPv4 or IPv6) of the origin server that the request was sent to. + * Examples: {@code 192.168.1.1}, {@code FE80::0202:B3FF:FE1E:8329}. + */ + public String getServerIp() { return serverIp; } @@ -305,7 +494,18 @@ public String serverIp() { * @see HTTP/1.1 Header Field * Definitions */ + @Deprecated public String referer() { + return getReferer(); + } + + /** + * Returns the referer URL of the request, as defined in HTTP/1.1 Header Field Definitions. + * + * @see HTTP/1.1 Header Field + * Definitions + */ + public String getReferer() { return referer; } @@ -338,7 +538,16 @@ public boolean cacheValidatedWithOriginServer() { * Returns the number of HTTP response bytes inserted into cache. Set only when a cache fill was * attempted. */ + @Deprecated public Long cacheFillBytes() { + return getCacheFillBytes(); + } + + /** + * Returns the number of HTTP response bytes inserted into cache. Set only when a cache fill was + * attempted. + */ + public Long getCacheFillBytes() { return cacheFillBytes; } @@ -423,7 +632,7 @@ com.google.logging.type.HttpRequest toPb() { if (remoteIp != null) { builder.setRemoteIp(remoteIp); } - if (serverIp != null) { + if (serverIp != null) { builder.setServerIp(serverIp); } if (referer != null) { @@ -441,44 +650,52 @@ com.google.logging.type.HttpRequest toPb() { /** * Returns a builder for {@code HttpRequest} objects. */ + @Deprecated public static Builder builder() { + return newBuilder(); + } + + /** + * Returns a builder for {@code HttpRequest} objects. + */ + public static Builder newBuilder() { return new Builder(); } static HttpRequest fromPb(com.google.logging.type.HttpRequest requestPb) { - Builder builder = builder(); + Builder builder = newBuilder(); if (requestPb.getRequestMethod() != null && !requestPb.getRequestMethod().equals("")) { - builder.requestMethod(RequestMethod.valueOf(requestPb.getRequestMethod())); + builder.setRequestMethod(RequestMethod.valueOf(requestPb.getRequestMethod())); } if (requestPb.getRequestUrl() != null && !requestPb.getRequestUrl().equals("")) { - builder.requestUrl(requestPb.getRequestUrl()); + builder.setRequestUrl(requestPb.getRequestUrl()); } if (requestPb.getRequestSize() != 0L) { - builder.requestSize(requestPb.getRequestSize()); + builder.setRequestSize(requestPb.getRequestSize()); } if (requestPb.getStatus() != 0L) { - builder.status(requestPb.getStatus()); + builder.setStatus(requestPb.getStatus()); } if (requestPb.getResponseSize() != 0L) { - builder.responseSize(requestPb.getResponseSize()); + builder.setResponseSize(requestPb.getResponseSize()); } if (requestPb.getUserAgent() != null && !requestPb.getRequestUrl().equals("")) { - builder.userAgent(requestPb.getUserAgent()); + builder.setUserAgent(requestPb.getUserAgent()); } if (requestPb.getServerIp() != null && !requestPb.getServerIp().equals("")) { - builder.serverIp(requestPb.getServerIp()); + builder.setServerIp(requestPb.getServerIp()); } if (requestPb.getRemoteIp() != null && !requestPb.getRemoteIp().equals("")) { - builder.remoteIp(requestPb.getRemoteIp()); + builder.setRemoteIp(requestPb.getRemoteIp()); } if (requestPb.getReferer() != null && !requestPb.getReferer().equals("")) { - builder.referer(requestPb.getReferer()); + builder.setReferer(requestPb.getReferer()); } - builder.cacheLookup(requestPb.getCacheLookup()); - builder.cacheHit(requestPb.getCacheHit()); - builder.cacheValidatedWithOriginServer(requestPb.getCacheValidatedWithOriginServer()); + builder.setCacheLookup(requestPb.getCacheLookup()); + builder.setCacheHit(requestPb.getCacheHit()); + builder.setCacheValidatedWithOriginServer(requestPb.getCacheValidatedWithOriginServer()); if (requestPb.getCacheFillBytes() != 0L) { - builder.cacheFillBytes(requestPb.getCacheFillBytes()); + builder.setCacheFillBytes(requestPb.getCacheFillBytes()); } return builder.build(); } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java index ab87a9cb710a..821c6e9b76af 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java @@ -102,7 +102,19 @@ public static class Builder { * forward-slash ({@code /}) characters in the log name must be URL-encoded. Examples: * {@code syslog}, {@code library.googleapis.com%2Fbook_log}. */ + @Deprecated public Builder logName(String logName) { + return setLogName(logName); + } + + /** + * Sets the name of the log to which this log entry belongs. The log name must be less than 512 + * characters long and can only include the following characters: upper and lower case + * alphanumeric characters: {@code [A-Za-z0-9]}; and punctuation characters: {@code _-./}. The + * forward-slash ({@code /}) characters in the log name must be URL-encoded. Examples: + * {@code syslog}, {@code library.googleapis.com%2Fbook_log}. + */ + public Builder setLogName(String logName) { this.logName = logName; return this; } @@ -112,7 +124,17 @@ public Builder logName(String logName) { * a database error would be associated with the monitored resource designating the particular * database that reported the error. */ + @Deprecated public Builder resource(MonitoredResource resource) { + return setResource(resource); + } + + /** + * Sets the monitored resource associated with this log entry. Example: a log entry that reports + * a database error would be associated with the monitored resource designating the particular + * database that reported the error. + */ + public Builder setResource(MonitoredResource resource) { this.resource = resource; return this; } @@ -121,7 +143,16 @@ public Builder resource(MonitoredResource resource) { * Sets the time at which the event described by the log entry occurred, in milliseconds. If * omitted, the Logging service will use the time at which the log entry is received. */ + @Deprecated public Builder timestamp(long timestamp) { + return setTimestamp(timestamp); + } + + /** + * Sets the time at which the event described by the log entry occurred, in milliseconds. If + * omitted, the Logging service will use the time at which the log entry is received. + */ + public Builder setTimestamp(long timestamp) { this.timestamp = timestamp; return this; } @@ -129,7 +160,15 @@ public Builder timestamp(long timestamp) { /** * Sets the severity of the log entry. If not set, {@link Severity#DEFAULT} is used. */ + @Deprecated public Builder severity(Severity severity) { + return setSeverity(severity); + } + + /** + * Sets the severity of the log entry. If not set, {@link Severity#DEFAULT} is used. + */ + public Builder setSeverity(Severity severity) { this.severity = severity; return this; } @@ -139,7 +178,17 @@ public Builder severity(Severity severity) { * other log entries in the same log with the same ID as duplicates which can be removed. If * omitted, the Logging service will generate a unique ID for this log entry. */ + @Deprecated public Builder insertId(String insertId) { + return setInsertId(insertId); + } + + /** + * Sets a unique ID for the log entry. If you provide this field, the Logging service considers + * other log entries in the same log with the same ID as duplicates which can be removed. If + * omitted, the Logging service will generate a unique ID for this log entry. + */ + public Builder setInsertId(String insertId) { this.insertId = insertId; return this; } @@ -147,7 +196,15 @@ public Builder insertId(String insertId) { /** * Sets information about the HTTP request associated with this log entry, if applicable. */ + @Deprecated public Builder httpRequest(HttpRequest httpRequest) { + return setHttpRequest(httpRequest); + } + + /** + * Sets information about the HTTP request associated with this log entry, if applicable. + */ + public Builder setHttpRequest(HttpRequest httpRequest) { this.httpRequest = httpRequest; return this; } @@ -156,7 +213,16 @@ public Builder httpRequest(HttpRequest httpRequest) { * Sets an optional set of user-defined (key, value) data that provides additional information * about the log entry. */ + @Deprecated public Builder labels(Map labels) { + return setLabels(labels); + } + + /** + * Sets an optional set of user-defined (key, value) data that provides additional information + * about the log entry. + */ + public Builder setLabels(Map labels) { this.labels = new HashMap<>(checkNotNull(labels)); return this; } @@ -182,7 +248,15 @@ public Builder clearLabels() { /** * Sets information about an operation associated with the log entry, if applicable. */ + @Deprecated public Builder operation(Operation operation) { + return setOperation(operation); + } + + /** + * Sets information about an operation associated with the log entry, if applicable. + */ + public Builder setOperation(Operation operation) { this.operation = operation; return this; } @@ -194,7 +268,19 @@ public Builder operation(Operation operation) { * * @see Log Entries and Logs */ + @Deprecated public Builder payload(Payload payload) { + return setPayload(payload); + } + + /** + * Sets the payload for this log entry. The log entry payload can be provided as an UTF-8 string + * (see {@link Payload.StringPayload}), a JSON object (see {@link Payload.JsonPayload}, or + * a protobuf object (see {@link Payload.ProtoPayload}). + * + * @see Log Entries and Logs + */ + public Builder setPayload(Payload payload) { this.payload = payload; return this; } @@ -226,7 +312,19 @@ public LogEntry build() { * forward-slash ({@code /}) characters in the log name must be URL-encoded. Examples: * {@code syslog}, {@code library.googleapis.com%2Fbook_log}. */ + @Deprecated public String logName() { + return getLogName(); + } + + /** + * Returns the name of the log to which this log entry belongs. The log name must be less than 512 + * characters long and can only include the following characters: upper and lower case + * alphanumeric characters: {@code [A-Za-z0-9]}; and punctuation characters: {@code _-./}. The + * forward-slash ({@code /}) characters in the log name must be URL-encoded. Examples: + * {@code syslog}, {@code library.googleapis.com%2Fbook_log}. + */ + public String getLogName() { return logName; } @@ -235,7 +333,17 @@ public String logName() { * reports a database error would be associated with the monitored resource designating the * particular database that reported the error. */ + @Deprecated public MonitoredResource resource() { + return getResource(); + } + + /** + * Returns the monitored resource associated with this log entry. Example: a log entry that + * reports a database error would be associated with the monitored resource designating the + * particular database that reported the error. + */ + public MonitoredResource getResource() { return resource; } @@ -243,14 +351,31 @@ public MonitoredResource resource() { * Returns the time at which the event described by the log entry occurred, in milliseconds. If * omitted, the Logging service will use the time at which the log entry is received. */ + @Deprecated public Long timestamp() { + return getTimestamp(); + } + + /** + * Returns the time at which the event described by the log entry occurred, in milliseconds. If + * omitted, the Logging service will use the time at which the log entry is received. + */ + public Long getTimestamp() { return timestamp; } /** * Returns the severity of the log entry. If not set, {@link Severity#DEFAULT} is used. */ + @Deprecated public Severity severity() { + return getSeverity(); + } + + /** + * Returns the severity of the log entry. If not set, {@link Severity#DEFAULT} is used. + */ + public Severity getSeverity() { return severity; } @@ -258,14 +383,31 @@ public Severity severity() { * Returns a unique ID for the log entry. The Logging service considers other log entries in the * same log with the same ID as duplicates which can be removed. */ + @Deprecated public String insertId() { + return getInsertId(); + } + + /** + * Returns a unique ID for the log entry. The Logging service considers other log entries in the + * same log with the same ID as duplicates which can be removed. + */ + public String getInsertId() { return insertId; } /** * Returns information about the HTTP request associated with this log entry, if applicable. */ + @Deprecated public HttpRequest httpRequest() { + return getHttpRequest(); + } + + /** + * Returns information about the HTTP request associated with this log entry, if applicable. + */ + public HttpRequest getHttpRequest() { return httpRequest; } @@ -273,14 +415,31 @@ public HttpRequest httpRequest() { * Returns an optional set of user-defined (key, value) data that provides additional information * about the log entry. */ + @Deprecated public Map labels() { + return getLabels(); + } + + /** + * Returns an optional set of user-defined (key, value) data that provides additional information + * about the log entry. + */ + public Map getLabels() { return labels; } /** * Returns information about an operation associated with the log entry, if applicable. */ + @Deprecated public Operation operation() { + return getOperation(); + } + + /** + * Returns information about an operation associated with the log entry, if applicable. + */ + public Operation getOperation() { return operation; } @@ -292,7 +451,20 @@ public Operation operation() { * @see Log Entries and Logs */ @SuppressWarnings("unchecked") + @Deprecated public T payload() { + return getPayload(); + } + + /** + * Returns the payload for this log entry. The log entry payload can be an UTF-8 string (see + * {@link Payload.StringPayload}), a JSON object (see {@link Payload.JsonPayload}, or a protobuf + * object (see {@link Payload.ProtoPayload}). + * + * @see Log Entries and Logs + */ + @SuppressWarnings("unchecked") + public T getPayload() { return (T) payload; } @@ -377,7 +549,15 @@ com.google.logging.v2.LogEntry toPb(String projectId) { /** * Returns a builder for {@code LogEntry} objects given the entry payload. */ + @Deprecated public static Builder builder(Payload payload) { + return newBuilder(payload); + } + + /** + * Returns a builder for {@code LogEntry} objects given the entry payload. + */ + public static Builder newBuilder(Payload payload) { return new Builder(payload); } @@ -385,7 +565,7 @@ public static Builder builder(Payload payload) { * Creates a {@code LogEntry} object given the entry payload. */ public static LogEntry of(Payload payload) { - return builder(payload).build(); + return newBuilder(payload).build(); } /** @@ -393,35 +573,35 @@ public static LogEntry of(Payload payload) { * payload. */ public static LogEntry of(String logName, MonitoredResource resource, Payload payload) { - return builder(payload).logName(logName).resource(resource).build(); + return newBuilder(payload).setLogName(logName).setResource(resource).build(); } static LogEntry fromPb(com.google.logging.v2.LogEntry entryPb) { - Builder builder = builder(Payload.fromPb(entryPb)); - builder.labels(entryPb.getLabels()); - builder.severity(Severity.fromPb(entryPb.getSeverity())); + Builder builder = newBuilder(Payload.fromPb(entryPb)); + builder.setLabels(entryPb.getLabelsMap()); + builder.setSeverity(Severity.fromPb(entryPb.getSeverity())); if (!entryPb.getLogName().equals("")) { - builder.logName(LoggingServiceV2Api.parseLogFromLogName(entryPb.getLogName())); + builder.setLogName(LoggingServiceV2Api.parseLogFromLogName(entryPb.getLogName())); } if (!entryPb.getResource().equals(com.google.api.MonitoredResource.getDefaultInstance())) { - builder.resource(MonitoredResource.fromPb(entryPb.getResource())); + builder.setResource(MonitoredResource.fromPb(entryPb.getResource())); } if (entryPb.hasTimestamp()) { Timestamp ts = entryPb.getTimestamp(); Long millis = ts.getSeconds() * MILLIS_PER_SECOND + ts.getNanos() / NANOS_PER_MILLISECOND; if (millis != 0) { - builder.timestamp(millis); + builder.setTimestamp(millis); } } if (!entryPb.getInsertId().equals("")) { - builder.insertId(entryPb.getInsertId()); + builder.setInsertId(entryPb.getInsertId()); } if (!entryPb.getHttpRequest().equals( com.google.logging.type.HttpRequest.getDefaultInstance())) { - builder.httpRequest(HttpRequest.fromPb(entryPb.getHttpRequest())); + builder.setHttpRequest(HttpRequest.fromPb(entryPb.getHttpRequest())); } if (!entryPb.getOperation().equals(LogEntryOperation.getDefaultInstance())) { - builder.operation(Operation.fromPb(entryPb.getOperation())); + builder.setOperation(Operation.fromPb(entryPb.getOperation())); } return builder.build(); } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java index 2f4b9c0b1cb7..0db8c916d5f8 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java @@ -234,9 +234,9 @@ public static EntryListOption filter(String filter) { *
 {@code
    * String sinkName = "my_sink_name";
    * String datasetName = "my_dataset";
-   * SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName))
-   *     .versionFormat(SinkInfo.VersionFormat.V2)
-   *     .filter("severity>=ERROR")
+   * SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName))
+   *     .setVersionFormat(SinkInfo.VersionFormat.V2)
+   *     .setFilter("severity>=ERROR")
    *     .build();
    * Sink sink = logging.update(sinkInfo);
    * }
@@ -255,9 +255,9 @@ public static EntryListOption filter(String filter) { *
 {@code
    * String sinkName = "my_sink_name";
    * String datasetName = "my_dataset";
-   * SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName))
-   *     .versionFormat(SinkInfo.VersionFormat.V2)
-   *     .filter("severity>=ERROR")
+   * SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName))
+   *     .setVersionFormat(SinkInfo.VersionFormat.V2)
+   *     .setFilter("severity>=ERROR")
    *     .build();
    * Future future = logging.updateAsync(sinkInfo);
    * // ...
@@ -274,7 +274,7 @@ public static EntryListOption filter(String filter) {
    * 
 {@code
    * String sinkName = "my_sink_name";
    * Sink sink = logging.getSink(sinkName);
-   * if (sink != null) {
+   * if (sink == null) {
    *   // sink was not found
    * }
    * }
@@ -293,7 +293,7 @@ public static EntryListOption filter(String filter) { * Future future = logging.getSinkAsync(sinkName); * // ... * Sink sink = future.get(); - * if (sink != null) { + * if (sink == null) { * // sink was not found * } * }
@@ -501,8 +501,8 @@ Future> listMonitoredResourceDescriptorsA *

Example of updating a metric. *

 {@code
    * String metricName = "my_metric_name";
-   * MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR")
-   *     .description("new description")
+   * MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR")
+   *     .setDescription("new description")
    *     .build();
    * Metric metric = logging.update(metricInfo);
    * }
@@ -520,8 +520,8 @@ Future> listMonitoredResourceDescriptorsA *

Example of asynchronously updating a metric. *

 {@code
    * String metricName = "my_metric_name";
-   * MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR")
-   *     .description("new description")
+   * MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR")
+   *     .setDescription("new description")
    *     .build();
    * Future future = logging.updateAsync(metricInfo);
    * // ...
@@ -538,7 +538,7 @@ Future> listMonitoredResourceDescriptorsA
    * 
 {@code
    * String metricName = "my_metric_name";
    * Metric metric = logging.getMetric(metricName);
-   * if (metric != null) {
+   * if (metric == null) {
    *   // metric was not found
    * }
    * }
@@ -557,7 +557,7 @@ Future> listMonitoredResourceDescriptorsA * Future future = logging.getMetricAsync(metricName); * // ... * Metric metric = future.get(); - * if (metric != null) { + * if (metric == null) { * // metric was not found * } * }
@@ -662,7 +662,7 @@ Future> listMonitoredResourceDescriptorsA * entries.add(LogEntry.of(JsonPayload.of(jsonMap))); * logging.write(entries, * WriteOption.logName(logName), - * WriteOption.resource(MonitoredResource.builder("global").build())); + * WriteOption.resource(MonitoredResource.newBuilder("global").build())); * } * */ @@ -688,7 +688,7 @@ Future> listMonitoredResourceDescriptorsA * Future future = logging.writeAsync( * entries, * WriteOption.logName(logName), - * WriteOption.resource(MonitoredResource.builder("global").build())); + * WriteOption.resource(MonitoredResource.newBuilder("global").build())); * } * */ diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java index 892dd374fc30..21eca656b972 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java @@ -147,7 +147,7 @@ public LoggingHandler(String log, LoggingOptions options, MonitoredResource moni setFilter(helper.getFilterProperty(className + ".filter", null)); setFormatter(helper.getFormatterProperty(className + ".formatter", new SimpleFormatter())); String logName = firstNonNull(log, helper.getProperty(className + ".log", "java.log")); - MonitoredResource resource = firstNonNull(monitoredResource, defaultResource()); + MonitoredResource resource = firstNonNull(monitoredResource, getDefaultResource()); writeOptions = new WriteOption[]{WriteOption.logName(logName), WriteOption.resource(resource)}; maskLoggers(); } @@ -207,7 +207,7 @@ private static boolean hasLoggingHandler(Logger logger) { return false; } - private MonitoredResource defaultResource() { + private MonitoredResource getDefaultResource() { return MonitoredResource.of("global", ImmutableMap.of("project_id", options.projectId())); } @@ -271,7 +271,7 @@ Formatter getFormatterProperty(String name, Formatter defaultValue) { /** * Returns an instance of the logging service. */ - Logging logging() { + Logging getLogging() { if (logging == null) { logging = options.service(); } @@ -306,15 +306,15 @@ private LogEntry entryFor(LogRecord record) { Map labels = ImmutableMap.of( "levelName", level.getName(), "levelValue", String.valueOf(level.intValue())); - return LogEntry.builder(Payload.StringPayload.of(payload)) - .labels(labels) - .severity(severityFor(level)) + return LogEntry.newBuilder(Payload.StringPayload.of(payload)) + .setLabels(labels) + .setSeverity(severityFor(level)) .build(); } private static Severity severityFor(Level level) { if (level instanceof LoggingLevel) { - return ((LoggingLevel) level).severity(); + return ((LoggingLevel) level).getSeverity(); } switch (level.intValue()) { // FINEST @@ -348,7 +348,7 @@ private static Severity severityFor(Level level) { * how entries should be written. */ void write(List entries, WriteOption... options) { - logging().write(entries, options); + getLogging().write(entries, options); } @Override diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java index 225aba62ced2..33736bf0c1d5 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java @@ -218,7 +218,7 @@ public Sink update(SinkInfo sink) { @Override public Future updateAsync(SinkInfo sink) { UpdateSinkRequest request = UpdateSinkRequest.newBuilder() - .setSinkName(ConfigServiceV2Api.formatSinkName(options().projectId(), sink.name())) + .setSinkName(ConfigServiceV2Api.formatSinkName(options().projectId(), sink.getName())) .setSink(sink.toPb(options().projectId())) .build(); return transform(rpc.update(request), Sink.fromPbFunction(this)); @@ -375,7 +375,8 @@ public Metric update(MetricInfo metric) { @Override public Future updateAsync(MetricInfo metric) { UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder() - .setMetricName(MetricsServiceV2Api.formatMetricName(options().projectId(), metric.name())) + .setMetricName(MetricsServiceV2Api.formatMetricName(options().projectId(), + metric.getName())) .setMetric(metric.toPb()) .build(); return transform(rpc.update(request), Metric.fromPbFunction(this)); @@ -542,7 +543,7 @@ public void close() throws Exception { static Map optionMap(Option... options) { Map optionMap = Maps.newHashMap(); for (Option option : options) { - Object prev = optionMap.put(option.optionType(), option.value()); + Object prev = optionMap.put(option.getOptionType(), option.getValue()); checkArgument(prev == null, "Duplicate option %s", option); } return optionMap; diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingLevel.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingLevel.java index 5ed4ae6d84b0..53056993a6d2 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingLevel.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingLevel.java @@ -89,7 +89,15 @@ private LoggingLevel(String name, int value, Severity severity) { /** * Returns the Stackdriver Logging severity associated with this logging level. */ + @Deprecated public Severity severity() { + return getSeverity(); + } + + /** + * Returns the Stackdriver Logging severity associated with this logging level. + */ + public Severity getSeverity() { return severity; } } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java index c5e3e6e00ff4..3be29ef1cd0d 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java @@ -58,20 +58,38 @@ private Builder(Metric metric) { } @Override + @Deprecated public Builder name(String name) { - delegate.name(name); + return setName(name); + } + + @Override + public Builder setName(String name) { + delegate.setName(name); return this; } @Override + @Deprecated public Builder description(String description) { - delegate.description(description); + return setDescription(description); + } + + @Override + public Builder setDescription(String description) { + delegate.setDescription(description); return this; } @Override + @Deprecated public Builder filter(String filter) { - delegate.filter(filter); + return setFilter(filter); + } + + @Override + public Builder setFilter(String filter) { + delegate.setFilter(filter); return this; } @@ -112,7 +130,15 @@ public final boolean equals(Object obj) { /** * Returns the metrics's {@code Logging} object used to issue requests. */ + @Deprecated public Logging logging() { + return getLogging(); + } + + /** + * Returns the metrics's {@code Logging} object used to issue requests. + */ + public Logging getLogging() { return logging; } @@ -133,7 +159,7 @@ public Logging logging() { * @throws LoggingException upon failure */ public boolean delete() { - return logging.deleteMetric(name()); + return logging.deleteMetric(getName()); } /** @@ -156,7 +182,7 @@ public boolean delete() { * @throws LoggingException upon failure */ public Future deleteAsync() { - return logging.deleteMetricAsync(name()); + return logging.deleteMetricAsync(getName()); } /** @@ -174,7 +200,7 @@ public Future deleteAsync() { * @throws LoggingException upon failure */ public Metric reload() { - return logging.getMetric(name()); + return logging.getMetric(getName()); } /** @@ -195,7 +221,7 @@ public Metric reload() { * @throws LoggingException upon failure */ public Future reloadAsync() { - return logging.getMetricAsync(name()); + return logging.getMetricAsync(getName()); } /** @@ -204,7 +230,7 @@ public Future reloadAsync() { *

Example of updating the metric's information. *

 {@code
    * Metric updatedMetric = metric.toBuilder()
-   *     .description("A more detailed description")
+   *     .setDescription("A more detailed description")
    *     .build()
    *     .update();
    * }
@@ -224,7 +250,7 @@ public Metric update() { *

Example of asynchronously updating the metric's information. *

 {@code
    * Future future = metric.toBuilder()
-   *     .description("A more detailed description")
+   *     .setDescription("A more detailed description")
    *     .build()
    *     .updateAsync();
    * // ...
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/MetricInfo.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/MetricInfo.java
index cd0cf58f4d6b..9be96f8d2ce8 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/MetricInfo.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/MetricInfo.java
@@ -51,13 +51,29 @@ public abstract static class Builder {
      * forward-slash character ({@code /}) denotes a hierarchy of name pieces, and it cannot be the
      * first character of the name.
      */
+    @Deprecated
     public abstract Builder name(String name);
 
+    /**
+     * Sets the name of the metric. Example: {@code severe-errors}. Metric identifiers are
+     * limited to 1000 characters and can include only the following characters: {@code A-Z},
+     * {@code a-z}, {@code 0-9}, and the special characters {@code _-.,+!*',()%/\}. The
+     * forward-slash character ({@code /}) denotes a hierarchy of name pieces, and it cannot be the
+     * first character of the name.
+     */
+    public abstract Builder setName(String name);
+
     /**
      * Sets an optional description for this metric. Used for documentation purpose.
      */
+    @Deprecated
     public abstract Builder description(String description);
 
+    /**
+     * Sets an optional description for this metric. Used for documentation purpose.
+     */
+    public abstract Builder setDescription(String description);
+
     /**
      * Sets an advanced logs filter. The value of the metric is the number of log entries that match
      * this filter. Example: {@code logName=projects/my-projectid/logs/syslog AND severity>=ERROR}.
@@ -65,8 +81,18 @@ public abstract static class Builder {
      * @see Advanced Log
      *     Filters
      */
+    @Deprecated
     public abstract Builder filter(String filter);
 
+    /**
+     * Sets an advanced logs filter. The value of the metric is the number of log entries that match
+     * this filter. Example: {@code logName=projects/my-projectid/logs/syslog AND severity>=ERROR}.
+     *
+     * @see Advanced Log
+     *     Filters
+     */
+    public abstract Builder setFilter(String filter);
+
     /**
      * Creates a {@code MetricInfo} object for this builder.
      */
@@ -91,19 +117,37 @@ static final class BuilderImpl extends Builder {
     }
 
     @Override
+    @Deprecated
     public Builder name(String name) {
+      return setName(name);
+    }
+
+    @Override
+    public Builder setName(String name) {
       this.name = name;
       return this;
     }
 
     @Override
+    @Deprecated
     public Builder description(String description) {
+      return setDescription(description);
+    }
+
+    @Override
+    public Builder setDescription(String description) {
       this.description = description;
       return this;
     }
 
     @Override
+    @Deprecated
     public Builder filter(String filter) {
+      return setFilter(filter);
+    }
+
+    @Override
+    public Builder setFilter(String filter) {
       this.filter = filter;
       return this;
     }
@@ -127,14 +171,34 @@ public MetricInfo build() {
    * forward-slash character ({@code /}) denotes a hierarchy of name pieces, and it cannot be the
    * first character of the name.
    */
+  @Deprecated
   public String name() {
+    return getName();
+  }
+
+  /**
+   * Returns the name of the metric. Example: {@code severe-errors}. Metric identifiers are
+   * limited to 1000 characters and can include only the following characters: {@code A-Z},
+   * {@code a-z}, {@code 0-9}, and the special characters {@code _-.,+!*',()%/\}. The
+   * forward-slash character ({@code /}) denotes a hierarchy of name pieces, and it cannot be the
+   * first character of the name.
+   */
+  public String getName() {
     return name;
   }
 
   /**
    * Returns an optional description for this metric. Used for documentation purpose.
    */
+  @Deprecated
   public String description() {
+    return getDescription();
+  }
+
+  /**
+   * Returns an optional description for this metric. Used for documentation purpose.
+   */
+  public String getDescription() {
     return description;
   }
 
@@ -146,7 +210,20 @@ public String description() {
    * @see Advanced Log
    *     Filters
    */
+  @Deprecated
   public String filter() {
+    return getFilter();
+  }
+
+  /**
+   * Returns an advanced logs filter. The value of the metric is the number of log entries that
+   * match this filter. Example:
+   * {@code logName=projects/my-projectid/logs/syslog AND severity>=ERROR}.
+   *
+   * @see Advanced Log
+   *     Filters
+   */
+  public String getFilter() {
     return filter;
   }
 
@@ -191,7 +268,15 @@ public Builder toBuilder() {
   /**
    * Returns a builder for {@code MetricInfo} objects given the name of the metric and its filter.
    */
+  @Deprecated
   public static Builder builder(String name, String filter) {
+    return newBuilder(name, filter);
+  }
+
+  /**
+   * Returns a builder for {@code MetricInfo} objects given the name of the metric and its filter.
+   */
+  public static Builder newBuilder(String name, String filter) {
     return new BuilderImpl(name, filter);
   }
 
@@ -213,9 +298,9 @@ LogMetric toPb() {
   }
 
   static MetricInfo fromPb(LogMetric metricPb) {
-    Builder builder = builder(metricPb.getName(), metricPb.getFilter());
+    Builder builder = newBuilder(metricPb.getName(), metricPb.getFilter());
     if (!metricPb.getDescription().equals("")) {
-      builder.description(metricPb.getDescription());
+      builder.setDescription(metricPb.getDescription());
     }
     return builder.build();
   }
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Operation.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Operation.java
index f36888895fcd..468f40feb733 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Operation.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Operation.java
@@ -67,7 +67,16 @@ public static final class Builder {
      * Sets the operation identifier. Log entries with the same identifier are assumed to be part
      * of the same operation. The combination of id and producer must be globally unique.
      */
+    @Deprecated
     public Builder id(String id) {
+      return setId(id);
+    }
+
+    /**
+     * Sets the operation identifier. Log entries with the same identifier are assumed to be part
+     * of the same operation. The combination of id and producer must be globally unique.
+     */
+    public Builder setId(String id) {
       this.id = id;
       return this;
     }
@@ -77,7 +86,17 @@ public Builder id(String id) {
      * unique. Examples: {@code MyDivision.MyBigCompany.com},
      * {@code github.com/MyProject/MyApplication}.
      */
+    @Deprecated
     public Builder producer(String producer) {
+      return setProducer(producer);
+    }
+
+    /**
+     * Sets an arbitrary producer identifier. The combination of producer and id must be globally
+     * unique. Examples: {@code MyDivision.MyBigCompany.com},
+     * {@code github.com/MyProject/MyApplication}.
+     */
+    public Builder setProducer(String producer) {
       this.producer = producer;
       return this;
     }
@@ -86,7 +105,16 @@ public Builder producer(String producer) {
      * Sets whether the corresponding entry is the first log entry in the operation. If not set,
      * {@code false} is used.
      */
+    @Deprecated
     public Builder first(boolean first) {
+      return setFirst(first);
+    }
+
+    /**
+     * Sets whether the corresponding entry is the first log entry in the operation. If not set,
+     * {@code false} is used.
+     */
+    public Builder setFirst(boolean first) {
       this.first = first;
       return this;
     }
@@ -95,7 +123,16 @@ public Builder first(boolean first) {
      * Sets whether the corresponding entry is the last log entry in the operation. If not set,
      * {@code false} is used.
      */
+    @Deprecated
     public Builder last(boolean last) {
+      return setLast(last);
+    }
+
+    /**
+     * Sets whether the corresponding entry is the last log entry in the operation. If not set,
+     * {@code false} is used.
+     */
+    public Builder setLast(boolean last) {
       this.last = last;
       return this;
     }
@@ -120,7 +157,17 @@ public Operation build() {
    * of the same operation. The combination of this value and {@link #producer()} must be globally
    * unique.
    */
+  @Deprecated
   public String id() {
+    return getId();
+  }
+
+  /**
+   * Returns the operation identifier. Log entries with the same identifier are assumed to be part
+   * of the same operation. The combination of this value and {@link #producer()} must be globally
+   * unique.
+   */
+  public String getId() {
     return id;
   }
 
@@ -129,7 +176,17 @@ public String id() {
    * must be globally unique. Examples: {@code MyDivision.MyBigCompany.com},
    * {@code github.com/MyProject/MyApplication}.
    */
+  @Deprecated
   public String producer() {
+    return getProducer();
+  }
+
+  /**
+   * Returns an arbitrary producer identifier. The combination of this value and {@link #id()}
+   * must be globally unique. Examples: {@code MyDivision.MyBigCompany.com},
+   * {@code github.com/MyProject/MyApplication}.
+   */
+  public String getProducer() {
     return producer;
   }
 
@@ -199,7 +256,16 @@ LogEntryOperation toPb() {
    * Returns a builder for {@code Operation} objects given the operation and producer identifiers.
    * The combination of producer and id must be globally unique.
    */
+  @Deprecated
   public static Builder builder(String id, String producer) {
+    return newBuilder(id, producer);
+  }
+
+  /**
+   * Returns a builder for {@code Operation} objects given the operation and producer identifiers.
+   * The combination of producer and id must be globally unique.
+   */
+  public static Builder newBuilder(String id, String producer) {
     return new Builder(id, producer);
   }
 
@@ -208,13 +274,13 @@ public static Builder builder(String id, String producer) {
    * combination of producer and id must be globally unique.
    */
   public static Operation of(String id, String producer) {
-    return builder(id, producer).build();
+    return newBuilder(id, producer).build();
   }
 
   static Operation fromPb(LogEntryOperation operationPb) {
-    return builder(operationPb.getId(), operationPb.getProducer())
-        .first(operationPb.getFirst())
-        .last(operationPb.getLast())
+    return newBuilder(operationPb.getId(), operationPb.getProducer())
+        .setFirst(operationPb.getFirst())
+        .setLast(operationPb.getLast())
         .build();
   }
 }
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Option.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Option.java
index 2e36d65fc4cd..6315ac8c8cde 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Option.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Option.java
@@ -43,11 +43,11 @@ interface OptionType {
   }
 
   @SuppressWarnings("unchecked")
-   T optionType() {
+   T getOptionType() {
     return (T) optionType;
   }
 
-  Object value() {
+  Object getValue() {
     return value;
   }
 
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Payload.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Payload.java
index 48510619db0b..c7b6a8a20f43 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Payload.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Payload.java
@@ -71,7 +71,7 @@ public static final class StringPayload extends Payload {
 
     @Override
     com.google.logging.v2.LogEntry.Builder toPb() {
-      return com.google.logging.v2.LogEntry.newBuilder().setTextPayload(data());
+      return com.google.logging.v2.LogEntry.newBuilder().setTextPayload(getData());
     }
 
     /**
@@ -100,13 +100,21 @@ public static final class JsonPayload extends Payload {
     /**
      * Returns the log entry's JSON data as an unmodifiable map.
      */
-    public Map dataAsMap() {
-      return Structs.asMap(data());
+    @Deprecated
+    public Map dataAsMap() {
+      return getDataAsMap();
+    }
+
+    /**
+     * Returns the log entry's JSON data as an unmodifiable map.
+     */
+    public Map getDataAsMap() {
+      return Structs.asMap(getData());
     }
 
     @Override
     com.google.logging.v2.LogEntry.Builder toPb() {
-      return com.google.logging.v2.LogEntry.newBuilder().setJsonPayload(data());
+      return com.google.logging.v2.LogEntry.newBuilder().setJsonPayload(getData());
     }
 
     /**
@@ -131,7 +139,7 @@ com.google.logging.v2.LogEntry.Builder toPb() {
      *   JsonPayload payload = JsonPayload.of(jsonContent);
      * }
*/ - public static JsonPayload of(Map data) { + public static JsonPayload of(Map data) { return new JsonPayload(Structs.newStruct(data)); } @@ -160,7 +168,7 @@ public static final class ProtoPayload extends Payload { @Override com.google.logging.v2.LogEntry.Builder toPb() { - return com.google.logging.v2.LogEntry.newBuilder().setProtoPayload(data()); + return com.google.logging.v2.LogEntry.newBuilder().setProtoPayload(getData()); } /** @@ -184,14 +192,31 @@ private Payload(Type type, T data) { * Returns the payload type. Payload can be an UTF-8 string ({@link Type#STRING}), a JSON object * ({@link Type#JSON}) or a protobuf object ({@link Type#PROTO}). */ + @Deprecated public Type type() { + return getType(); + } + + /** + * Returns the payload type. Payload can be an UTF-8 string ({@link Type#STRING}), a JSON object + * ({@link Type#JSON}) or a protobuf object ({@link Type#PROTO}). + */ + public Type getType() { return type; } /** * Returns the log entry payload's data. */ + @Deprecated public T data() { + return getData(); + } + + /** + * Returns the log entry payload's data. + */ + public T getData() { return data; } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java index 4a2aede6b62a..5ebac1896896 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java @@ -64,26 +64,50 @@ private Builder(Sink sink) { } @Override + @Deprecated public Builder name(String name) { - delegate.name(name); + return setName(name); + } + + @Override + public Builder setName(String name) { + delegate.setName(name); return this; } @Override + @Deprecated public Builder destination(Destination destination) { - delegate.destination(destination); + return setDestination(destination); + } + + @Override + public Builder setDestination(Destination destination) { + delegate.setDestination(destination); return this; } @Override + @Deprecated public Builder filter(String filter) { - delegate.filter(filter); + return setFilter(filter); + } + + @Override + public Builder setFilter(String filter) { + delegate.setFilter(filter); return this; } @Override + @Deprecated public Builder versionFormat(VersionFormat versionFormat) { - delegate.versionFormat(versionFormat); + return setVersionFormat(versionFormat); + } + + @Override + public Builder setVersionFormat(VersionFormat versionFormat) { + delegate.setVersionFormat(versionFormat); return this; } @@ -124,7 +148,15 @@ public final boolean equals(Object obj) { /** * Returns the sinks's {@code Logging} object used to issue requests. */ + @Deprecated public Logging logging() { + return getLogging(); + } + + /** + * Returns the sinks's {@code Logging} object used to issue requests. + */ + public Logging getLogging() { return logging; } @@ -145,7 +177,7 @@ public Logging logging() { * @throws LoggingException upon failure */ public boolean delete() { - return logging.deleteSink(name()); + return logging.deleteSink(getName()); } /** @@ -168,7 +200,7 @@ public boolean delete() { * @throws LoggingException upon failure */ public Future deleteAsync() { - return logging.deleteSinkAsync(name()); + return logging.deleteSinkAsync(getName()); } /** @@ -186,7 +218,7 @@ public Future deleteAsync() { * @throws LoggingException upon failure */ public Sink reload() { - return logging.getSink(name()); + return logging.getSink(getName()); } /** @@ -207,7 +239,7 @@ public Sink reload() { * @throws LoggingException upon failure */ public Future reloadAsync() { - return logging.getSinkAsync(name()); + return logging.getSinkAsync(getName()); } /** @@ -216,7 +248,7 @@ public Future reloadAsync() { *

Example of updating the sink's information. *

 {@code
    * Sink updatedSink = sink.toBuilder()
-   *     .filter("severity<=ERROR")
+   *     .setFilter("severity<=ERROR")
    *     .build()
    *     .update();
    * }
@@ -236,7 +268,7 @@ public Sink update() { *

Example of asynchronously updating the sink's information. *

 {@code
    * Future future = sink.toBuilder()
-   *     .filter("severity<=ERROR")
+   *     .setFilter("severity<=ERROR")
    *     .build()
    *     .updateAsync();
    * // ...
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java
index c2669ac07bae..af218c2b3a11 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java
@@ -95,7 +95,15 @@ public static final class BucketDestination extends Destination {
       /**
        * Returns the name of the Google Cloud Storage bucket this destination represents.
        */
+      @Deprecated
       public String bucket() {
+        return getBucket();
+      }
+
+      /**
+       * Returns the name of the Google Cloud Storage bucket this destination represents.
+       */
+      public String getBucket() {
         return bucket;
       }
 
@@ -171,14 +179,31 @@ public static final class DatasetDestination extends Destination {
        * Returns the name of the project where the Google Cloud BigQuery dataset resides. If
        * {@code null}, the default project is used.
        */
+      @Deprecated
       public String project() {
+        return getProject();
+      }
+
+      /**
+       * Returns the name of the project where the Google Cloud BigQuery dataset resides. If
+       * {@code null}, the default project is used.
+       */
+      public String getProject() {
         return project;
       }
 
       /**
        * Returns the name of the Google Cloud BigQuery dataset this destination represents.
        */
+      @Deprecated
       public String dataset() {
+        return getDataset();
+      }
+
+      /**
+       * Returns the name of the Google Cloud BigQuery dataset this destination represents.
+       */
+      public String getDataset() {
         return dataset;
       }
 
@@ -267,14 +292,31 @@ public static final class TopicDestination extends Destination {
        * Returns the name of the project where the Google Cloud Pub/Sub topic resides. If
        * {@code null}, the default project is used.
        */
+      @Deprecated
       public String project() {
+        return getProject();
+      }
+
+      /**
+       * Returns the name of the project where the Google Cloud Pub/Sub topic resides. If
+       * {@code null}, the default project is used.
+       */
+      public String getProject() {
         return project;
       }
 
       /**
        * Returns the name of the Google Cloud Pub/Sub topic this destination represents.
        */
+      @Deprecated
       public String topic() {
+        return getTopic();
+      }
+
+      /**
+       * Returns the name of the Google Cloud Pub/Sub topic this destination represents.
+       */
+      public String getTopic() {
         return topic;
       }
 
@@ -347,7 +389,15 @@ static TopicDestination fromPb(String destinationPb) {
     /**
      * Returns the type of this destination.
      */
+    @Deprecated
     public Type type() {
+      return getType();
+    }
+
+    /**
+     * Returns the type of this destination.
+     */
+    public Type getType() {
       return type;
     }
 
@@ -416,8 +466,16 @@ public abstract static class Builder {
      * limited to 1000 characters and can include only the following characters: {@code A-Z},
      * {@code a-z}, {@code 0-9}, and the special characters {@code _-.}.
      */
+    @Deprecated
     public abstract Builder name(String name);
 
+    /**
+     * Sets the name of the sink. Example: {@code my-severe-errors-to-pubsub}. Sink identifiers are
+     * limited to 1000 characters and can include only the following characters: {@code A-Z},
+     * {@code a-z}, {@code 0-9}, and the special characters {@code _-.}.
+     */
+    public abstract Builder setName(String name);
+
     /**
      * Sets the export destination. Use a {@link Destination.BucketDestination} object to create a
      * sink that exports logs to a Google Cloud Storage bucket. Use a
@@ -428,8 +486,21 @@ public abstract static class Builder {
      * @see 
      *     Exporting Logs
      */
+    @Deprecated
     public abstract Builder destination(Destination destination);
 
+    /**
+     * Sets the export destination. Use a {@link Destination.BucketDestination} object to create a
+     * sink that exports logs to a Google Cloud Storage bucket. Use a
+     * {@link Destination.DatasetDestination} object to create a sink that exports logs to a Google
+     * Cloud BigQuery dataset. Use a {@link Destination.TopicDestination} object to create a sink
+     * that exports logs to a Google Cloud Pub/Sub topic.
+     *
+     * @see 
+     *     Exporting Logs
+     */
+    public abstract Builder setDestination(Destination destination);
+
     /**
      * Sets an advanced logs filter. Only log entries matching that filter are exported. The filter
      * must be consistent with the log entry format specified with
@@ -440,15 +511,36 @@ public abstract static class Builder {
      * @see Advanced Log
      *     Filters
      */
+    @Deprecated
     public abstract Builder filter(String filter);
 
+    /**
+     * Sets an advanced logs filter. Only log entries matching that filter are exported. The filter
+     * must be consistent with the log entry format specified with
+     * {@link #versionFormat(VersionFormat)}, regardless of the format of the log entry that was
+     * originally written to Stackdriver Logging. Example (V2 format):
+     * {@code logName=projects/my-projectid/logs/syslog AND severity>=ERROR}.
+     *
+     * @see Advanced Log
+     *     Filters
+     */
+    public abstract Builder setFilter(String filter);
+
     /**
      * Sets the log entry version to use for this sink's exported log entries. This version does
      * not have to correspond to the version of the log entry when it was written to Google Cloud
      * Logging.
      */
+    @Deprecated
     public abstract Builder versionFormat(VersionFormat versionFormat);
 
+    /**
+     * Sets the log entry version to use for this sink's exported log entries. This version does
+     * not have to correspond to the version of the log entry when it was written to Google Cloud
+     * Logging.
+     */
+    public abstract Builder setVersionFormat(VersionFormat versionFormat);
+
     /**
      * Creates a {@code SinkInfo} object for this builder.
      */
@@ -475,25 +567,49 @@ static final class BuilderImpl extends Builder {
     }
 
     @Override
+    @Deprecated
     public Builder name(String name) {
+      return setName(name);
+    }
+
+    @Override
+    public Builder setName(String name) {
       this.name = name;
       return this;
     }
 
     @Override
+    @Deprecated
     public Builder destination(Destination destination) {
+      return setDestination(destination);
+    }
+
+    @Override
+    public Builder setDestination(Destination destination) {
       this.destination = destination;
       return this;
     }
 
     @Override
+    @Deprecated
     public Builder filter(String filter) {
+      return setFilter(filter);
+    }
+
+    @Override
+    public Builder setFilter(String filter) {
       this.filter = filter;
       return this;
     }
 
     @Override
+    @Deprecated
     public Builder versionFormat(VersionFormat versionFormat) {
+      return setVersionFormat(versionFormat);
+    }
+
+    @Override
+    public Builder setVersionFormat(VersionFormat versionFormat) {
       this.versionFormat = versionFormat;
       return this;
     }
@@ -516,7 +632,17 @@ public SinkInfo build() {
    * limited to 1000 characters and can include only the following characters: {@code A-Z},
    * {@code a-z}, {@code 0-9}, and the special characters {@code _-.}.
    */
+  @Deprecated
   public String name() {
+    return getName();
+  }
+
+  /**
+   * Returns the name of the sink. Example: {@code my-severe-errors-to-pubsub}. Sink identifiers are
+   * limited to 1000 characters and can include only the following characters: {@code A-Z},
+   * {@code a-z}, {@code 0-9}, and the special characters {@code _-.}.
+   */
+  public String getName() {
     return name;
   }
 
@@ -531,7 +657,23 @@ public String name() {
    *     Exporting Logs
    */
   @SuppressWarnings("unchecked")
+  @Deprecated
   public  T destination() {
+    return getDestination();
+  }
+
+  /**
+   * Returns the export destination. This method returns a {@link Destination.BucketDestination} for
+   * sinks that export logs to Google Cloud Storage buckets. Returns
+   * {@link Destination.DatasetDestination} for sinks that export logs to Google Cloud BigQuery
+   * datasets. Returns {@link Destination.TopicDestination} for sinks that export logs to Google
+   * Cloud Pub/Sub topics.
+   *
+   * @see 
+   *     Exporting Logs
+   */
+  @SuppressWarnings("unchecked")
+  public  T getDestination() {
     return (T) destination;
   }
 
@@ -544,7 +686,21 @@ public  T destination() {
    * @see Advanced Log
    *     Filters
    */
+  @Deprecated
   public String filter() {
+    return getFilter();
+  }
+
+  /**
+   * Returns an advanced logs filter. Only log entries matching that filter are exported. The filter
+   * must be consistent with the log entry format specified in {@link #versionFormat()}, regardless
+   * of the format of the log entry that wa originally written to Stackdriver Logging. Example (V2
+   * format): {@code logName=projects/my-projectid/logs/syslog AND severity>=ERROR}.
+   *
+   * @see Advanced Log
+   *     Filters
+   */
+  public String getFilter() {
     return filter;
   }
 
@@ -553,7 +709,17 @@ public String filter() {
    * not have to correspond to the version of the log entry when it was written to Google Cloud
    * Logging.
    */
+  @Deprecated
   public VersionFormat versionFormat() {
+    return getVersionFormat();
+  }
+
+  /**
+   * Returns the log entry version to use for this sink's exported log entries. This version does
+   * not have to correspond to the version of the log entry when it was written to Google Cloud
+   * Logging.
+   */
+  public VersionFormat getVersionFormat() {
     return versionFormat;
   }
 
@@ -600,7 +766,15 @@ public Builder toBuilder() {
   /**
    * Returns a builder for {@code SinkInfo} objects given the name of the sink and its destination.
    */
+  @Deprecated
   public static Builder builder(String name, Destination destination) {
+    return newBuilder(name, destination);
+  }
+
+  /**
+   * Returns a builder for {@code SinkInfo} objects given the name of the sink and its destination.
+   */
+  public static Builder newBuilder(String name, Destination destination) {
     return new BuilderImpl(name, destination);
   }
 
@@ -624,11 +798,11 @@ LogSink toPb(String projectId) {
   }
 
   static SinkInfo fromPb(LogSink sinkPb) {
-    Builder builder = builder(sinkPb.getName(),
+    Builder builder = newBuilder(sinkPb.getName(),
         Destination.fromPb(sinkPb.getDestination()))
-        .versionFormat(VersionFormat.fromPb(sinkPb.getOutputVersionFormat()));
+        .setVersionFormat(VersionFormat.fromPb(sinkPb.getOutputVersionFormat()));
     if (!sinkPb.getFilter().equals("")) {
-      builder.filter(sinkPb.getFilter());
+      builder.setFilter(sinkPb.getFilter());
     }
     return builder.build();
   }
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Structs.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Structs.java
index 1e77cbd7c916..52605c739f5c 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Structs.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Structs.java
@@ -86,12 +86,12 @@ private StructSet(Struct struct) {
 
       @Override
       public Iterator> iterator() {
-        return Iterators.transform(struct.getFields().entrySet().iterator(), VALUE_TO_OBJECT);
+        return Iterators.transform(struct.getFieldsMap().entrySet().iterator(), VALUE_TO_OBJECT);
       }
 
       @Override
       public int size() {
-        return struct.getFields().size();
+        return struct.getFieldsMap().size();
       }
     }
 
@@ -114,7 +114,7 @@ static Map asMap(Struct struct) {
    * 

Notice that all numbers (int, long, float and double) are serialized as double values. * Enums are serialized as strings. */ - static Struct newStruct(Map map) { + static Struct newStruct(Map map) { Map valueMap = Maps.transformValues(checkNotNull(map), OBJECT_TO_VALUE); return Struct.newBuilder().putAllFields(valueMap).build(); } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java index 244533e69a21..ab456dc1c615 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java @@ -25,9 +25,9 @@ * LoggingOptions options = LoggingOptions.defaultInstance(); * try(Logging logging = options.service()) { * - * LogEntry firstEntry = LogEntry.builder(StringPayload.of("message")) - * .logName("test-log") - * .resource(MonitoredResource.builder("global") + * LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message")) + * .setLogName("test-log") + * .setResource(MonitoredResource.builder("global") * .addLabel("project_id", options.projectId()) * .build()) * .build(); diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/RemoteLoggingHelper.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/RemoteLoggingHelper.java index 48b7c183d5a8..65bb9bfaa0d7 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/RemoteLoggingHelper.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/RemoteLoggingHelper.java @@ -28,8 +28,8 @@ /** * Utility to create a remote logging configuration for testing. Logging options can be obtained via - * the {@link #options()} method. Returned options have custom {@link LoggingOptions#retryParams()}: - * {@link RetryParams#maxRetryDelayMillis()} is {@code 30000}, + * the {@link #getOptions()} method. Returned options have custom + * {@link LoggingOptions#retryParams()}: {@link RetryParams#maxRetryDelayMillis()} is {@code 30000}, * {@link RetryParams#totalRetryPeriodMillis()} is {@code 120000} and * {@link RetryParams#initialRetryDelayMillis()} is {@code 250}. * {@link LoggingOptions#initialTimeout()} is set to 60000, {@link LoggingOptions#maxTimeout()} is @@ -47,7 +47,15 @@ private RemoteLoggingHelper(LoggingOptions options) { /** * Returns a {@link LoggingOptions} object to be used for testing. */ + @Deprecated public LoggingOptions options() { + return getOptions(); + } + + /** + * Returns a {@link LoggingOptions} object to be used for testing. + */ + public LoggingOptions getOptions() { return options; } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java index 59ac80ff542f..3c765aab6095 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java @@ -22,7 +22,7 @@ *

Before the test: *

 {@code
  * RemoteLoggingHelper helper = RemoteLoggingHelper.create();
- * Logging logging = helper.options().service();
+ * Logging logging = helper.getOptions().service();
  * } 
* *

Format resource names to avoid name clashes: diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/AsyncLoggingHandlerTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/AsyncLoggingHandlerTest.java index b10d649bdf2d..e555a6b3cbe3 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/AsyncLoggingHandlerTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/AsyncLoggingHandlerTest.java @@ -61,8 +61,8 @@ public void afterClass() { public void testPublish() { EasyMock.expect(options.projectId()).andReturn(PROJECT).anyTimes(); EasyMock.expect(options.service()).andReturn(logging); - LogEntry entry = LogEntry.builder(Payload.StringPayload.of(MESSAGE)) - .severity(Severity.DEBUG) + LogEntry entry = LogEntry.newBuilder(Payload.StringPayload.of(MESSAGE)) + .setSeverity(Severity.DEBUG) .addLabel("levelName", "FINEST") .addLabel("levelValue", String.valueOf(Level.FINEST.intValue())) .build(); diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java index 2d1dff31026c..eb523b0dddcf 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java @@ -90,25 +90,25 @@ public abstract class BaseSystemTest { @Test public void testCreateGetUpdateAndDeleteSink() { String name = formatForTest("test-create-get-update-sink"); - SinkInfo sinkInfo = SinkInfo.builder(name, DatasetDestination.of("dataset")) - .filter("severity>=ERROR") - .versionFormat(SinkInfo.VersionFormat.V2) + SinkInfo sinkInfo = SinkInfo.newBuilder(name, DatasetDestination.of("dataset")) + .setFilter("severity>=ERROR") + .setVersionFormat(SinkInfo.VersionFormat.V2) .build(); Sink sink = logging().create(sinkInfo); - assertEquals(name, sink.name()); - assertEquals(SinkInfo.VersionFormat.V2, sink.versionFormat()); - assertEquals("severity>=ERROR", sink.filter()); - DatasetDestination datasetDestination = sink.destination(); - assertEquals(logging().options().projectId(), datasetDestination.project()); - assertEquals("dataset", datasetDestination.dataset()); + assertEquals(name, sink.getName()); + assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); + assertEquals("severity>=ERROR", sink.getFilter()); + DatasetDestination datasetDestination = sink.getDestination(); + assertEquals(logging().options().projectId(), datasetDestination.getProject()); + assertEquals("dataset", datasetDestination.getDataset()); assertEquals(sink, logging().getSink(name)); sink = sink.toBuilder() - .filter("severity<=ERROR") + .setFilter("severity<=ERROR") .build() .update(); - assertEquals(name, sink.name()); - assertEquals(SinkInfo.VersionFormat.V2, sink.versionFormat()); - assertEquals("severity<=ERROR", sink.filter()); + assertEquals(name, sink.getName()); + assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); + assertEquals("severity<=ERROR", sink.getFilter()); assertTrue(sink.delete()); assertFalse(sink.delete()); } @@ -117,25 +117,25 @@ public void testCreateGetUpdateAndDeleteSink() { public void testCreateGetUpdateAndDeleteSinkAsync() throws ExecutionException, InterruptedException { String name = formatForTest("test-create-get-update-sink-async"); - SinkInfo sinkInfo = SinkInfo.builder(name, DatasetDestination.of("dataset")) - .filter("severity>=ERROR") - .versionFormat(SinkInfo.VersionFormat.V2) + SinkInfo sinkInfo = SinkInfo.newBuilder(name, DatasetDestination.of("dataset")) + .setFilter("severity>=ERROR") + .setVersionFormat(SinkInfo.VersionFormat.V2) .build(); Sink sink = logging().createAsync(sinkInfo).get(); - assertEquals(name, sink.name()); - assertEquals(SinkInfo.VersionFormat.V2, sink.versionFormat()); - assertEquals("severity>=ERROR", sink.filter()); - DatasetDestination datasetDestination = sink.destination(); - assertEquals(logging().options().projectId(), datasetDestination.project()); - assertEquals("dataset", datasetDestination.dataset()); + assertEquals(name, sink.getName()); + assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); + assertEquals("severity>=ERROR", sink.getFilter()); + DatasetDestination datasetDestination = sink.getDestination(); + assertEquals(logging().options().projectId(), datasetDestination.getProject()); + assertEquals("dataset", datasetDestination.getDataset()); assertEquals(sink, logging().getSinkAsync(name).get()); sink = sink.toBuilder() - .filter("severity<=ERROR") + .setFilter("severity<=ERROR") .build() .updateAsync().get(); - assertEquals(name, sink.name()); - assertEquals(SinkInfo.VersionFormat.V2, sink.versionFormat()); - assertEquals("severity<=ERROR", sink.filter()); + assertEquals(name, sink.getName()); + assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); + assertEquals("severity<=ERROR", sink.getFilter()); assertTrue(sink.deleteAsync().get()); assertFalse(sink.deleteAsync().get()); } @@ -143,36 +143,36 @@ public void testCreateGetUpdateAndDeleteSinkAsync() @Test public void testUpdateNonExistingSink() { String name = formatForTest("test-update-non-existing-sink"); - SinkInfo sinkInfo = SinkInfo.builder(name, DatasetDestination.of("dataset")) - .filter("severity>=ERROR") - .versionFormat(SinkInfo.VersionFormat.V2) + SinkInfo sinkInfo = SinkInfo.newBuilder(name, DatasetDestination.of("dataset")) + .setFilter("severity>=ERROR") + .setVersionFormat(SinkInfo.VersionFormat.V2) .build(); assertNull(logging().getSink(name)); Sink sink = logging().update(sinkInfo); - assertEquals(name, sink.name()); - assertEquals(SinkInfo.VersionFormat.V2, sink.versionFormat()); - assertEquals("severity>=ERROR", sink.filter()); - DatasetDestination datasetDestination = sink.destination(); - assertEquals(logging().options().projectId(), datasetDestination.project()); - assertEquals("dataset", datasetDestination.dataset()); + assertEquals(name, sink.getName()); + assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); + assertEquals("severity>=ERROR", sink.getFilter()); + DatasetDestination datasetDestination = sink.getDestination(); + assertEquals(logging().options().projectId(), datasetDestination.getProject()); + assertEquals("dataset", datasetDestination.getDataset()); assertTrue(logging().deleteSink(name)); } @Test public void testUpdateNonExistingSinkAsync() throws ExecutionException, InterruptedException { String name = formatForTest("test-update-non-existing-sink-async"); - SinkInfo sinkInfo = SinkInfo.builder(name, DatasetDestination.of("dataset")) - .filter("severity>=ERROR") - .versionFormat(SinkInfo.VersionFormat.V2) + SinkInfo sinkInfo = SinkInfo.newBuilder(name, DatasetDestination.of("dataset")) + .setFilter("severity>=ERROR") + .setVersionFormat(SinkInfo.VersionFormat.V2) .build(); assertNull(logging().getSinkAsync(name).get()); Sink sink = logging().updateAsync(sinkInfo).get(); - assertEquals(name, sink.name()); - assertEquals(SinkInfo.VersionFormat.V2, sink.versionFormat()); - assertEquals("severity>=ERROR", sink.filter()); - DatasetDestination datasetDestination = sink.destination(); - assertEquals(logging().options().projectId(), datasetDestination.project()); - assertEquals("dataset", datasetDestination.dataset()); + assertEquals(name, sink.getName()); + assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); + assertEquals("severity>=ERROR", sink.getFilter()); + DatasetDestination datasetDestination = sink.getDestination(); + assertEquals(logging().options().projectId(), datasetDestination.getProject()); + assertEquals("dataset", datasetDestination.getDataset()); assertTrue(logging().deleteSinkAsync(name).get()); } @@ -216,7 +216,7 @@ public void testListMonitoredResourceDescriptors() { logging().listMonitoredResourceDescriptors(Logging.ListOption.pageSize(1)).iterateAll(); Set descriptorTypes = new HashSet<>(); while (iterator.hasNext()) { - descriptorTypes.add(iterator.next().type()); + descriptorTypes.add(iterator.next().getType()); } for (String type : DESCRIPTOR_TYPES) { assertTrue(descriptorTypes.contains(type)); @@ -230,7 +230,7 @@ public void testListMonitoredResourceDescriptorsAsync() .listMonitoredResourceDescriptorsAsync(Logging.ListOption.pageSize(1)).get().iterateAll(); Set descriptorTypes = new HashSet<>(); while (iterator.hasNext()) { - descriptorTypes.add(iterator.next().type()); + descriptorTypes.add(iterator.next().getType()); } for (String type : DESCRIPTOR_TYPES) { assertTrue(descriptorTypes.contains(type)); @@ -240,22 +240,22 @@ public void testListMonitoredResourceDescriptorsAsync() @Test public void testCreateGetUpdateAndDeleteMetric() { String name = formatForTest("test-create-get-update-metric"); - MetricInfo metricInfo = MetricInfo.builder(name, "severity>=ERROR") - .description("description") + MetricInfo metricInfo = MetricInfo.newBuilder(name, "severity>=ERROR") + .setDescription("description") .build(); Metric metric = logging().create(metricInfo); - assertEquals(name, metric.name()); - assertEquals("severity>=ERROR", metric.filter()); - assertEquals("description", metric.description()); + assertEquals(name, metric.getName()); + assertEquals("severity>=ERROR", metric.getFilter()); + assertEquals("description", metric.getDescription()); assertEquals(metric, logging().getMetric(name)); metric = metric.toBuilder() - .description("newDescription") - .filter("severity>=WARNING") + .setDescription("newDescription") + .setFilter("severity>=WARNING") .build() .update(); - assertEquals(name, metric.name()); - assertEquals("severity>=WARNING", metric.filter()); - assertEquals("newDescription", metric.description()); + assertEquals(name, metric.getName()); + assertEquals("severity>=WARNING", metric.getFilter()); + assertEquals("newDescription", metric.getDescription()); assertTrue(metric.delete()); assertFalse(metric.delete()); } @@ -264,22 +264,22 @@ public void testCreateGetUpdateAndDeleteMetric() { public void testCreateGetUpdateAndDeleteMetricAsync() throws ExecutionException, InterruptedException { String name = formatForTest("test-create-get-update-metric-async"); - MetricInfo metricInfo = MetricInfo.builder(name, "severity>=ERROR") - .description("description") + MetricInfo metricInfo = MetricInfo.newBuilder(name, "severity>=ERROR") + .setDescription("description") .build(); Metric metric = logging().createAsync(metricInfo).get(); - assertEquals(name, metric.name()); - assertEquals("severity>=ERROR", metric.filter()); - assertEquals("description", metric.description()); + assertEquals(name, metric.getName()); + assertEquals("severity>=ERROR", metric.getFilter()); + assertEquals("description", metric.getDescription()); assertEquals(metric, logging().getMetricAsync(name).get()); metric = metric.toBuilder() - .description("newDescription") - .filter("severity>=WARNING") + .setDescription("newDescription") + .setFilter("severity>=WARNING") .build() .updateAsync().get(); - assertEquals(name, metric.name()); - assertEquals("severity>=WARNING", metric.filter()); - assertEquals("newDescription", metric.description()); + assertEquals(name, metric.getName()); + assertEquals("severity>=WARNING", metric.getFilter()); + assertEquals("newDescription", metric.getDescription()); assertTrue(metric.deleteAsync().get()); assertFalse(metric.deleteAsync().get()); } @@ -287,28 +287,28 @@ public void testCreateGetUpdateAndDeleteMetricAsync() @Test public void testUpdateNonExistingMetric() { String name = formatForTest("test-update-non-existing-metric"); - MetricInfo metricInfo = MetricInfo.builder(name, "severity>=ERROR") - .description("description") + MetricInfo metricInfo = MetricInfo.newBuilder(name, "severity>=ERROR") + .setDescription("description") .build(); assertNull(logging().getMetric(name)); Metric metric = logging().update(metricInfo); - assertEquals(name, metric.name()); - assertEquals("severity>=ERROR", metric.filter()); - assertEquals("description", metric.description()); + assertEquals(name, metric.getName()); + assertEquals("severity>=ERROR", metric.getFilter()); + assertEquals("description", metric.getDescription()); assertTrue(metric.delete()); } @Test public void testUpdateNonExistingMetricAsync() throws ExecutionException, InterruptedException { String name = formatForTest("test-update-non-existing-metric-async"); - MetricInfo metricInfo = MetricInfo.builder(name, "severity>=ERROR") - .description("description") + MetricInfo metricInfo = MetricInfo.newBuilder(name, "severity>=ERROR") + .setDescription("description") .build(); assertNull(logging().getMetricAsync(name).get()); Metric metric = logging().updateAsync(metricInfo).get(); - assertEquals(name, metric.name()); - assertEquals("severity>=ERROR", metric.filter()); - assertEquals("description", metric.description()); + assertEquals(name, metric.getName()); + assertEquals("severity>=ERROR", metric.getFilter()); + assertEquals("description", metric.getDescription()); assertTrue(metric.deleteAsync().get()); } @@ -351,19 +351,19 @@ public void testWriteAndListLogEntries() throws InterruptedException { String logName = formatForTest("test-write-log-entries-log"); String filter = "logName = projects/" + logging().options().projectId() + "/logs/" + logName; StringPayload firstPayload = StringPayload.of("stringPayload"); - LogEntry firstEntry = LogEntry.builder(firstPayload) + LogEntry firstEntry = LogEntry.newBuilder(firstPayload) .addLabel("key1", "value1") - .logName(logName) - .httpRequest(HttpRequest.builder().status(500).build()) - .resource(MonitoredResource.builder("global").build()) + .setLogName(logName) + .setHttpRequest(HttpRequest.newBuilder().setStatus(500).build()) + .setResource(MonitoredResource.newBuilder("global").build()) .build(); JsonPayload secondPayload = JsonPayload.of(ImmutableMap.of("jsonKey", "jsonValue")); - LogEntry secondEntry = LogEntry.builder(secondPayload) + LogEntry secondEntry = LogEntry.newBuilder(secondPayload) .addLabel("key2", "value2") - .logName(logName) - .operation(Operation.of("operationId", "operationProducer")) - .resource(MonitoredResource.builder("cloudsql_database").build()) + .setLogName(logName) + .setOperation(Operation.of("operationId", "operationProducer")) + .setResource(MonitoredResource.newBuilder("cloudsql_database").build()) .build(); logging().write(ImmutableList.of(firstEntry)); logging().write(ImmutableList.of(secondEntry)); @@ -376,32 +376,32 @@ public void testWriteAndListLogEntries() throws InterruptedException { Iterator iterator = page.iterateAll(); assertTrue(iterator.hasNext()); LogEntry entry = iterator.next(); - assertEquals(firstPayload, entry.payload()); - assertEquals(logName, entry.logName()); - assertEquals(ImmutableMap.of("key1", "value1"), entry.labels()); - assertEquals("global", entry.resource().type()); - assertEquals(HttpRequest.builder().status(500).build(), entry.httpRequest()); - assertEquals(Severity.DEFAULT, entry.severity()); - assertNull(entry.operation()); - assertNotNull(entry.insertId()); - assertNotNull(entry.timestamp()); + assertEquals(firstPayload, entry.getPayload()); + assertEquals(logName, entry.getLogName()); + assertEquals(ImmutableMap.of("key1", "value1"), entry.getLabels()); + assertEquals("global", entry.getResource().getType()); + assertEquals(HttpRequest.newBuilder().setStatus(500).build(), entry.getHttpRequest()); + assertEquals(Severity.DEFAULT, entry.getSeverity()); + assertNull(entry.getOperation()); + assertNotNull(entry.getInsertId()); + assertNotNull(entry.getTimestamp()); assertTrue(iterator.hasNext()); entry = iterator.next(); - assertEquals(secondPayload, entry.payload()); - assertEquals(logName, entry.logName()); - assertEquals(ImmutableMap.of("key2", "value2"), entry.labels()); - assertEquals("cloudsql_database", entry.resource().type()); - assertEquals(Operation.of("operationId", "operationProducer"), entry.operation()); - assertEquals(Severity.DEFAULT, entry.severity()); - assertNull(entry.httpRequest()); - assertNotNull(entry.insertId()); - assertNotNull(entry.timestamp()); + assertEquals(secondPayload, entry.getPayload()); + assertEquals(logName, entry.getLogName()); + assertEquals(ImmutableMap.of("key2", "value2"), entry.getLabels()); + assertEquals("cloudsql_database", entry.getResource().getType()); + assertEquals(Operation.of("operationId", "operationProducer"), entry.getOperation()); + assertEquals(Severity.DEFAULT, entry.getSeverity()); + assertNull(entry.getHttpRequest()); + assertNotNull(entry.getInsertId()); + assertNotNull(entry.getTimestamp()); page = logging().listLogEntries(EntryListOption.filter(filter), EntryListOption.sortOrder(SortingField.TIMESTAMP, SortingOrder.DESCENDING)); iterator = page.iterateAll(); - Long lastTimestamp = iterator.next().timestamp(); + Long lastTimestamp = iterator.next().getTimestamp(); while (iterator.hasNext()) { - assertTrue(iterator.next().timestamp() <= lastTimestamp); + assertTrue(iterator.next().getTimestamp() <= lastTimestamp); } assertTrue(logging().deleteLog(logName)); } @@ -411,13 +411,13 @@ public void testWriteAndListLogEntriesAsync() throws InterruptedException, Execu String logName = formatForTest("test-write-log-entries-async-log"); String filter = "logName = projects/" + logging().options().projectId() + "/logs/" + logName; StringPayload firstPayload = StringPayload.of("stringPayload"); - LogEntry firstEntry = LogEntry.builder(firstPayload).severity(Severity.ALERT).build(); + LogEntry firstEntry = LogEntry.newBuilder(firstPayload).setSeverity(Severity.ALERT).build(); ProtoPayload secondPayload = ProtoPayload.of(Any.pack(StringValue.newBuilder().setValue("protoPayload").build())); - LogEntry secondEntry = LogEntry.builder(secondPayload).severity(Severity.DEBUG).build(); + LogEntry secondEntry = LogEntry.newBuilder(secondPayload).setSeverity(Severity.DEBUG).build(); logging().writeAsync(ImmutableList.of(firstEntry, secondEntry), WriteOption.labels(ImmutableMap.of("key1", "value1")), - WriteOption.resource(MonitoredResource.builder("global").build()), + WriteOption.resource(MonitoredResource.newBuilder("global").build()), WriteOption.logName(logName)).get(); EntryListOption[] options = {EntryListOption.filter(filter), EntryListOption.pageSize(1)}; AsyncPage page = logging().listLogEntriesAsync(options).get(); @@ -428,26 +428,26 @@ public void testWriteAndListLogEntriesAsync() throws InterruptedException, Execu Iterator iterator = page.iterateAll(); assertTrue(iterator.hasNext()); LogEntry entry = iterator.next(); - assertEquals(firstPayload, entry.payload()); - assertEquals(logName, entry.logName()); - assertEquals(ImmutableMap.of("key1", "value1"), entry.labels()); - assertEquals("global", entry.resource().type()); - assertNull(entry.httpRequest()); - assertEquals(Severity.ALERT, entry.severity()); - assertNull(entry.operation()); - assertNotNull(entry.insertId()); - assertNotNull(entry.timestamp()); + assertEquals(firstPayload, entry.getPayload()); + assertEquals(logName, entry.getLogName()); + assertEquals(ImmutableMap.of("key1", "value1"), entry.getLabels()); + assertEquals("global", entry.getResource().getType()); + assertNull(entry.getHttpRequest()); + assertEquals(Severity.ALERT, entry.getSeverity()); + assertNull(entry.getOperation()); + assertNotNull(entry.getInsertId()); + assertNotNull(entry.getTimestamp()); assertTrue(iterator.hasNext()); entry = iterator.next(); - assertEquals(secondPayload, entry.payload()); - assertEquals(logName, entry.logName()); - assertEquals(ImmutableMap.of("key1", "value1"), entry.labels()); - assertEquals("global", entry.resource().type()); - assertNull(entry.operation()); - assertEquals(Severity.DEBUG, entry.severity()); - assertNull(entry.httpRequest()); - assertNotNull(entry.insertId()); - assertNotNull(entry.timestamp()); + assertEquals(secondPayload, entry.getPayload()); + assertEquals(logName, entry.getLogName()); + assertEquals(ImmutableMap.of("key1", "value1"), entry.getLabels()); + assertEquals("global", entry.getResource().getType()); + assertNull(entry.getOperation()); + assertEquals(Severity.DEBUG, entry.getSeverity()); + assertNull(entry.getHttpRequest()); + assertNotNull(entry.getInsertId()); + assertNotNull(entry.getTimestamp()); assertTrue(logging().deleteLogAsync(logName).get()); } @@ -482,18 +482,19 @@ public void testLoggingHandler() throws InterruptedException { } assertTrue(iterator.hasNext()); LogEntry entry = iterator.next(); - assertTrue(entry.payload() instanceof StringPayload); - assertTrue(entry.payload().data().contains("Message")); - assertEquals(logName, entry.logName()); + assertTrue(entry.getPayload() instanceof StringPayload); + assertTrue(entry.getPayload().getData().contains("Message")); + assertEquals(logName, entry.getLogName()); assertEquals(ImmutableMap.of("levelName", "INFO", - "levelValue", String.valueOf(Level.INFO.intValue())), entry.labels()); - assertEquals("global", entry.resource().type()); - assertEquals(ImmutableMap.of("project_id", options.projectId()), entry.resource().labels()); - assertNull(entry.httpRequest()); - assertEquals(Severity.INFO, entry.severity()); - assertNull(entry.operation()); - assertNotNull(entry.insertId()); - assertNotNull(entry.timestamp()); + "levelValue", String.valueOf(Level.INFO.intValue())), entry.getLabels()); + assertEquals("global", entry.getResource().getType()); + assertEquals(ImmutableMap.of("project_id", options.projectId()), + entry.getResource().getLabels()); + assertNull(entry.getHttpRequest()); + assertEquals(Severity.INFO, entry.getSeverity()); + assertNull(entry.getOperation()); + assertNotNull(entry.getInsertId()); + assertNotNull(entry.getTimestamp()); assertFalse(iterator.hasNext()); logger.removeHandler(handler); logging().deleteLog(logName); @@ -522,17 +523,17 @@ public void testAsyncLoggingHandler() throws InterruptedException { } assertTrue(iterator.hasNext()); LogEntry entry = iterator.next(); - assertTrue(entry.payload() instanceof StringPayload); - assertTrue(entry.payload().data().contains("Message")); - assertEquals(logName, entry.logName()); + assertTrue(entry.getPayload() instanceof StringPayload); + assertTrue(entry.getPayload().getData().contains("Message")); + assertEquals(logName, entry.getLogName()); assertEquals(ImmutableMap.of("levelName", "WARNING", - "levelValue", String.valueOf(Level.WARNING.intValue())), entry.labels()); - assertEquals(resource, entry.resource()); - assertNull(entry.httpRequest()); - assertEquals(Severity.WARNING, entry.severity()); - assertNull(entry.operation()); - assertNotNull(entry.insertId()); - assertNotNull(entry.timestamp()); + "levelValue", String.valueOf(Level.WARNING.intValue())), entry.getLabels()); + assertEquals(resource, entry.getResource()); + assertNull(entry.getHttpRequest()); + assertEquals(Severity.WARNING, entry.getSeverity()); + assertNull(entry.getOperation()); + assertNotNull(entry.getInsertId()); + assertNotNull(entry.getTimestamp()); assertFalse(iterator.hasNext()); logger.removeHandler(handler); logging().deleteLog(logName); diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/HttpRequestTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/HttpRequestTest.java index 41eba99b327a..ca8fece87ee0 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/HttpRequestTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/HttpRequestTest.java @@ -43,7 +43,22 @@ public class HttpRequestTest { private static final boolean CACHE_HIT = true; private static final boolean CACHE_VALIDATED_WITH_ORIGIN_SERVER = false; private static final Long CACHE_FILL_BYTES = 3L; - private static final HttpRequest HTTP_REQUEST = HttpRequest.builder() + private static final HttpRequest HTTP_REQUEST = HttpRequest.newBuilder() + .setRequestMethod(REQUEST_METHOD) + .setRequestUrl(REQUEST_URL) + .setRequestSize(REQUEST_SIZE) + .setStatus(STATUS) + .setResponseSize(REPONSE_SIZE) + .setUserAgent(USER_AGENT) + .setRemoteIp(REMOTE_IP) + .setServerIp(SERVER_IP) + .setReferer(REFERER) + .setCacheLookup(CACHE_LOOKUP) + .setCacheHit(CACHE_HIT) + .setCacheValidatedWithOriginServer(CACHE_VALIDATED_WITH_ORIGIN_SERVER) + .setCacheFillBytes(CACHE_FILL_BYTES) + .build(); + private static final HttpRequest DEPRECATED_HTTP_REQUEST = HttpRequest.builder() .requestMethod(REQUEST_METHOD) .requestUrl(REQUEST_URL) .requestSize(REQUEST_SIZE) @@ -64,122 +79,140 @@ public class HttpRequestTest { @Test public void testBuilder() { - assertEquals(REQUEST_METHOD, HTTP_REQUEST.requestMethod()); - assertEquals(REQUEST_URL, HTTP_REQUEST.requestUrl()); - assertEquals(REQUEST_SIZE, HTTP_REQUEST.requestSize()); - assertEquals(STATUS, HTTP_REQUEST.status()); - assertEquals(REPONSE_SIZE, HTTP_REQUEST.responseSize()); - assertEquals(USER_AGENT, HTTP_REQUEST.userAgent()); - assertEquals(REMOTE_IP, HTTP_REQUEST.remoteIp()); - assertEquals(SERVER_IP, HTTP_REQUEST.serverIp()); - assertEquals(REFERER, HTTP_REQUEST.referer()); + assertEquals(REQUEST_METHOD, HTTP_REQUEST.getRequestMethod()); + assertEquals(REQUEST_URL, HTTP_REQUEST.getRequestUrl()); + assertEquals(REQUEST_SIZE, HTTP_REQUEST.getRequestSize()); + assertEquals(STATUS, HTTP_REQUEST.getStatus()); + assertEquals(REPONSE_SIZE, HTTP_REQUEST.getResponseSize()); + assertEquals(USER_AGENT, HTTP_REQUEST.getUserAgent()); + assertEquals(REMOTE_IP, HTTP_REQUEST.getRemoteIp()); + assertEquals(SERVER_IP, HTTP_REQUEST.getServerIp()); + assertEquals(REFERER, HTTP_REQUEST.getReferer()); assertEquals(CACHE_LOOKUP, HTTP_REQUEST.cacheLookup()); assertEquals(CACHE_HIT, HTTP_REQUEST.cacheHit()); assertEquals(CACHE_VALIDATED_WITH_ORIGIN_SERVER, HTTP_REQUEST.cacheValidatedWithOriginServer()); - assertEquals(CACHE_FILL_BYTES, HTTP_REQUEST.cacheFillBytes()); + assertEquals(CACHE_FILL_BYTES, HTTP_REQUEST.getCacheFillBytes()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(REQUEST_METHOD, DEPRECATED_HTTP_REQUEST.requestMethod()); + assertEquals(REQUEST_URL, DEPRECATED_HTTP_REQUEST.requestUrl()); + assertEquals(REQUEST_SIZE, DEPRECATED_HTTP_REQUEST.requestSize()); + assertEquals(STATUS, DEPRECATED_HTTP_REQUEST.status()); + assertEquals(REPONSE_SIZE, DEPRECATED_HTTP_REQUEST.responseSize()); + assertEquals(USER_AGENT, DEPRECATED_HTTP_REQUEST.userAgent()); + assertEquals(REMOTE_IP, DEPRECATED_HTTP_REQUEST.remoteIp()); + assertEquals(SERVER_IP, DEPRECATED_HTTP_REQUEST.serverIp()); + assertEquals(REFERER, DEPRECATED_HTTP_REQUEST.referer()); + assertEquals(CACHE_LOOKUP, DEPRECATED_HTTP_REQUEST.cacheLookup()); + assertEquals(CACHE_HIT, DEPRECATED_HTTP_REQUEST.cacheHit()); + assertEquals(CACHE_VALIDATED_WITH_ORIGIN_SERVER, + DEPRECATED_HTTP_REQUEST.cacheValidatedWithOriginServer()); + assertEquals(CACHE_FILL_BYTES, DEPRECATED_HTTP_REQUEST.cacheFillBytes()); } @Test public void testBuilderDefaultValues() { - HttpRequest httpRequest = HttpRequest.builder().build(); - assertNull(httpRequest.requestMethod()); - assertNull(httpRequest.requestUrl()); - assertNull(httpRequest.requestSize()); - assertNull(httpRequest.status()); - assertNull(httpRequest.responseSize()); - assertNull(httpRequest.userAgent()); - assertNull(httpRequest.remoteIp()); - assertNull(httpRequest.serverIp()); - assertNull(httpRequest.referer()); + HttpRequest httpRequest = HttpRequest.newBuilder().build(); + assertNull(httpRequest.getRequestMethod()); + assertNull(httpRequest.getRequestUrl()); + assertNull(httpRequest.getRequestSize()); + assertNull(httpRequest.getStatus()); + assertNull(httpRequest.getResponseSize()); + assertNull(httpRequest.getUserAgent()); + assertNull(httpRequest.getRemoteIp()); + assertNull(httpRequest.getServerIp()); + assertNull(httpRequest.getReferer()); assertFalse(httpRequest.cacheLookup()); assertFalse(httpRequest.cacheHit()); assertFalse(httpRequest.cacheValidatedWithOriginServer()); - assertNull(httpRequest.cacheFillBytes()); + assertNull(httpRequest.getCacheFillBytes()); } @Test public void testToBuilder() { compareHttpRequest(HTTP_REQUEST, HTTP_REQUEST.toBuilder().build()); HttpRequest httpRequest = HTTP_REQUEST.toBuilder() - .requestMethod(RequestMethod.POST) - .requestUrl("http://www.other-example.com") - .requestSize(4) - .status(201) - .responseSize(5) - .userAgent("otherUserAgent") - .remoteIp("192.168.1.3") - .serverIp("192.168.1.4") - .referer("Referer: http://www.other-example.com") - .cacheLookup(true) - .cacheHit(true) - .cacheValidatedWithOriginServer(true) - .cacheFillBytes(6) + .setRequestMethod(RequestMethod.POST) + .setRequestUrl("http://www.other-example.com") + .setRequestSize(4) + .setStatus(201) + .setResponseSize(5) + .setUserAgent("otherUserAgent") + .setRemoteIp("192.168.1.3") + .setServerIp("192.168.1.4") + .setReferer("Referer: http://www.other-example.com") + .setCacheLookup(true) + .setCacheHit(true) + .setCacheValidatedWithOriginServer(true) + .setCacheFillBytes(6) .build(); - assertEquals(RequestMethod.POST, httpRequest.requestMethod()); - assertEquals("http://www.other-example.com", httpRequest.requestUrl()); - assertEquals(4, (long) httpRequest.requestSize()); - assertEquals(201, (int) httpRequest.status()); - assertEquals(5, (long) httpRequest.responseSize()); - assertEquals("otherUserAgent", httpRequest.userAgent()); - assertEquals("192.168.1.3", httpRequest.remoteIp()); - assertEquals("192.168.1.4", httpRequest.serverIp()); - assertEquals("Referer: http://www.other-example.com", httpRequest.referer()); + assertEquals(RequestMethod.POST, httpRequest.getRequestMethod()); + assertEquals("http://www.other-example.com", httpRequest.getRequestUrl()); + assertEquals(4, (long) httpRequest.getRequestSize()); + assertEquals(201, (int) httpRequest.getStatus()); + assertEquals(5, (long) httpRequest.getResponseSize()); + assertEquals("otherUserAgent", httpRequest.getUserAgent()); + assertEquals("192.168.1.3", httpRequest.getRemoteIp()); + assertEquals("192.168.1.4", httpRequest.getServerIp()); + assertEquals("Referer: http://www.other-example.com", httpRequest.getReferer()); assertTrue(httpRequest.cacheLookup()); assertTrue(httpRequest.cacheHit()); assertTrue(httpRequest.cacheValidatedWithOriginServer()); - assertEquals(6, (long) httpRequest.cacheFillBytes()); + assertEquals(6, (long) httpRequest.getCacheFillBytes()); } @Test public void testToAndFromPb() { HttpRequest httpRequest = HttpRequest.fromPb(HTTP_REQUEST.toPb()); compareHttpRequest(HTTP_REQUEST, httpRequest); - assertEquals(REQUEST_METHOD, httpRequest.requestMethod()); - assertEquals(REQUEST_URL, httpRequest.requestUrl()); - assertEquals(REQUEST_SIZE, httpRequest.requestSize()); - assertEquals(STATUS, httpRequest.status()); - assertEquals(REPONSE_SIZE, httpRequest.responseSize()); - assertEquals(USER_AGENT, httpRequest.userAgent()); - assertEquals(REMOTE_IP, httpRequest.remoteIp()); - assertEquals(SERVER_IP, httpRequest.serverIp()); - assertEquals(REFERER, httpRequest.referer()); + assertEquals(REQUEST_METHOD, httpRequest.getRequestMethod()); + assertEquals(REQUEST_URL, httpRequest.getRequestUrl()); + assertEquals(REQUEST_SIZE, httpRequest.getRequestSize()); + assertEquals(STATUS, httpRequest.getStatus()); + assertEquals(REPONSE_SIZE, httpRequest.getResponseSize()); + assertEquals(USER_AGENT, httpRequest.getUserAgent()); + assertEquals(REMOTE_IP, httpRequest.getRemoteIp()); + assertEquals(SERVER_IP, httpRequest.getServerIp()); + assertEquals(REFERER, httpRequest.getReferer()); assertEquals(CACHE_LOOKUP, httpRequest.cacheLookup()); assertEquals(CACHE_HIT, httpRequest.cacheHit()); assertEquals(CACHE_VALIDATED_WITH_ORIGIN_SERVER, httpRequest.cacheValidatedWithOriginServer()); - assertEquals(CACHE_FILL_BYTES, httpRequest.cacheFillBytes()); - HttpRequest incompleteHttpRequest = HttpRequest.builder().build(); + assertEquals(CACHE_FILL_BYTES, httpRequest.getCacheFillBytes()); + HttpRequest incompleteHttpRequest = HttpRequest.newBuilder().build(); httpRequest = HttpRequest.fromPb(incompleteHttpRequest.toPb()); compareHttpRequest(incompleteHttpRequest, httpRequest); - assertNull(httpRequest.requestMethod()); - assertNull(httpRequest.requestUrl()); - assertNull(httpRequest.requestSize()); - assertNull(httpRequest.status()); - assertNull(httpRequest.responseSize()); - assertNull(httpRequest.userAgent()); - assertNull(httpRequest.remoteIp()); - assertNull(httpRequest.serverIp()); - assertNull(httpRequest.referer()); + assertNull(httpRequest.getRequestMethod()); + assertNull(httpRequest.getRequestUrl()); + assertNull(httpRequest.getRequestSize()); + assertNull(httpRequest.getStatus()); + assertNull(httpRequest.getResponseSize()); + assertNull(httpRequest.getUserAgent()); + assertNull(httpRequest.getRemoteIp()); + assertNull(httpRequest.getServerIp()); + assertNull(httpRequest.getReferer()); assertFalse(httpRequest.cacheLookup()); assertFalse(httpRequest.cacheHit()); assertFalse(httpRequest.cacheValidatedWithOriginServer()); - assertNull(httpRequest.cacheFillBytes()); + assertNull(httpRequest.getCacheFillBytes()); } private void compareHttpRequest(HttpRequest expected, HttpRequest value) { assertEquals(expected, value); - assertEquals(expected.requestMethod(), value.requestMethod()); - assertEquals(expected.requestUrl(), value.requestUrl()); - assertEquals(expected.requestSize(), value.requestSize()); - assertEquals(expected.status(), value.status()); - assertEquals(expected.responseSize(), value.responseSize()); - assertEquals(expected.userAgent(), value.userAgent()); - assertEquals(expected.remoteIp(), value.remoteIp()); - assertEquals(expected.serverIp(), value.serverIp()); - assertEquals(expected.referer(), value.referer()); + assertEquals(expected.getRequestMethod(), value.getRequestMethod()); + assertEquals(expected.getRequestUrl(), value.getRequestUrl()); + assertEquals(expected.getRequestSize(), value.getRequestSize()); + assertEquals(expected.getStatus(), value.getStatus()); + assertEquals(expected.getResponseSize(), value.getResponseSize()); + assertEquals(expected.getUserAgent(), value.getUserAgent()); + assertEquals(expected.getRemoteIp(), value.getRemoteIp()); + assertEquals(expected.getServerIp(), value.getServerIp()); + assertEquals(expected.getReferer(), value.getReferer()); assertEquals(expected.cacheLookup(), value.cacheLookup()); assertEquals(expected.cacheHit(), value.cacheHit()); assertEquals(expected.cacheValidatedWithOriginServer(), value.cacheValidatedWithOriginServer()); - assertEquals(expected.cacheFillBytes(), value.cacheFillBytes()); + assertEquals(expected.getCacheFillBytes(), value.getCacheFillBytes()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/LogEntryTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/LogEntryTest.java index ff2f93676b41..0f6c0f1c7d94 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/LogEntryTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/LogEntryTest.java @@ -34,15 +34,16 @@ public class LogEntryTest { private static final String LOG_NAME = "syslog"; - private static final MonitoredResource RESOURCE = MonitoredResource.builder("cloudsql_database") - .labels(ImmutableMap.of("datasetId", "myDataset", "zone", "myZone")) - .build(); + private static final MonitoredResource RESOURCE = + MonitoredResource.newBuilder("cloudsql_database") + .setLabels(ImmutableMap.of("datasetId", "myDataset", "zone", "myZone")) + .build(); private static final long TIMESTAMP = 42; private static final Severity SEVERITY = Severity.ALERT; private static final String INSERT_ID = "insertId"; - private static final HttpRequest HTTP_REQUEST = HttpRequest.builder() - .requestMethod(HttpRequest.RequestMethod.GET) - .status(404) + private static final HttpRequest HTTP_REQUEST = HttpRequest.newBuilder() + .setRequestMethod(HttpRequest.RequestMethod.GET) + .setStatus(404) .build(); private static final Map LABELS = ImmutableMap.of("key1", "value1", "key2", "value2"); @@ -52,7 +53,37 @@ public class LogEntryTest { JsonPayload.of(ImmutableMap.of("key", "val")); private static final ProtoPayload PROTO_PAYLOAD = ProtoPayload.of(Any.pack(Empty.getDefaultInstance())); - private static final LogEntry STRING_ENTRY = LogEntry.builder(STRING_PAYLOAD) + private static final LogEntry STRING_ENTRY = LogEntry.newBuilder(STRING_PAYLOAD) + .setLogName(LOG_NAME) + .setResource(RESOURCE) + .setTimestamp(TIMESTAMP) + .setSeverity(SEVERITY) + .setInsertId(INSERT_ID) + .setHttpRequest(HTTP_REQUEST) + .setLabels(LABELS) + .setOperation(OPERATION) + .build(); + private static final LogEntry JSON_ENTRY = LogEntry.newBuilder(JSON_PAYLOAD) + .setLogName(LOG_NAME) + .setResource(RESOURCE) + .setTimestamp(TIMESTAMP) + .setSeverity(SEVERITY) + .setInsertId(INSERT_ID) + .setHttpRequest(HTTP_REQUEST) + .setLabels(LABELS) + .setOperation(OPERATION) + .build(); + private static final LogEntry PROTO_ENTRY = LogEntry.newBuilder(PROTO_PAYLOAD) + .setLogName(LOG_NAME) + .setResource(RESOURCE) + .setTimestamp(TIMESTAMP) + .setSeverity(SEVERITY) + .setInsertId(INSERT_ID) + .setHttpRequest(HTTP_REQUEST) + .setLabels(LABELS) + .setOperation(OPERATION) + .build(); + private static final LogEntry DEPRECATED_STRING_ENTRY = LogEntry.builder(STRING_PAYLOAD) .logName(LOG_NAME) .resource(RESOURCE) .timestamp(TIMESTAMP) @@ -62,7 +93,7 @@ public class LogEntryTest { .labels(LABELS) .operation(OPERATION) .build(); - private static final LogEntry JSON_ENTRY = LogEntry.builder(JSON_PAYLOAD) + private static final LogEntry DEPRECATED_JSON_ENTRY = LogEntry.builder(JSON_PAYLOAD) .logName(LOG_NAME) .resource(RESOURCE) .timestamp(TIMESTAMP) @@ -72,7 +103,7 @@ public class LogEntryTest { .labels(LABELS) .operation(OPERATION) .build(); - private static final LogEntry PROTO_ENTRY = LogEntry.builder(PROTO_PAYLOAD) + private static final LogEntry DEPRECATED_PROTO_ENTRY = LogEntry.builder(PROTO_PAYLOAD) .logName(LOG_NAME) .resource(RESOURCE) .timestamp(TIMESTAMP) @@ -86,57 +117,109 @@ public class LogEntryTest { @Test public void testOf() { LogEntry logEntry = LogEntry.of(STRING_PAYLOAD); - assertEquals(STRING_PAYLOAD, logEntry.payload()); - assertEquals(Severity.DEFAULT, logEntry.severity()); - assertEquals(ImmutableMap.of(), logEntry.labels()); - assertNull(logEntry.logName()); - assertNull(logEntry.resource()); - assertNull(logEntry.timestamp()); - assertNull(logEntry.insertId()); - assertNull(logEntry.httpRequest()); - assertNull(logEntry.operation()); + assertEquals(STRING_PAYLOAD, logEntry.getPayload()); + assertEquals(Severity.DEFAULT, logEntry.getSeverity()); + assertEquals(ImmutableMap.of(), logEntry.getLabels()); + assertNull(logEntry.getLogName()); + assertNull(logEntry.getResource()); + assertNull(logEntry.getTimestamp()); + assertNull(logEntry.getInsertId()); + assertNull(logEntry.getHttpRequest()); + assertNull(logEntry.getOperation()); logEntry = LogEntry.of(LOG_NAME, RESOURCE, STRING_PAYLOAD); - assertEquals(STRING_PAYLOAD, logEntry.payload()); - assertEquals(LOG_NAME, logEntry.logName()); - assertEquals(RESOURCE, logEntry.resource()); - assertEquals(Severity.DEFAULT, logEntry.severity()); - assertEquals(ImmutableMap.of(), logEntry.labels()); - assertEquals(ImmutableMap.of(), logEntry.labels()); - assertNull(logEntry.timestamp()); - assertNull(logEntry.insertId()); - assertNull(logEntry.httpRequest()); - assertNull(logEntry.operation()); + assertEquals(STRING_PAYLOAD, logEntry.getPayload()); + assertEquals(LOG_NAME, logEntry.getLogName()); + assertEquals(RESOURCE, logEntry.getResource()); + assertEquals(Severity.DEFAULT, logEntry.getSeverity()); + assertEquals(ImmutableMap.of(), logEntry.getLabels()); + assertEquals(ImmutableMap.of(), logEntry.getLabels()); + assertNull(logEntry.getTimestamp()); + assertNull(logEntry.getInsertId()); + assertNull(logEntry.getHttpRequest()); + assertNull(logEntry.getOperation()); } @Test public void testBuilder() { - assertEquals(LOG_NAME, STRING_ENTRY.logName()); - assertEquals(RESOURCE, STRING_ENTRY.resource()); - assertEquals(TIMESTAMP, (long) STRING_ENTRY.timestamp()); - assertEquals(SEVERITY, STRING_ENTRY.severity()); - assertEquals(INSERT_ID, STRING_ENTRY.insertId()); - assertEquals(HTTP_REQUEST, STRING_ENTRY.httpRequest()); - assertEquals(LABELS, STRING_ENTRY.labels()); - assertEquals(OPERATION, STRING_ENTRY.operation()); - assertEquals(STRING_PAYLOAD, STRING_ENTRY.payload()); - assertEquals(LOG_NAME, JSON_ENTRY.logName()); - assertEquals(RESOURCE, JSON_ENTRY.resource()); - assertEquals(TIMESTAMP, (long) JSON_ENTRY.timestamp()); - assertEquals(SEVERITY, JSON_ENTRY.severity()); - assertEquals(INSERT_ID, JSON_ENTRY.insertId()); - assertEquals(HTTP_REQUEST, JSON_ENTRY.httpRequest()); - assertEquals(LABELS, JSON_ENTRY.labels()); - assertEquals(OPERATION, JSON_ENTRY.operation()); - assertEquals(JSON_PAYLOAD, JSON_ENTRY.payload()); - assertEquals(LOG_NAME, PROTO_ENTRY.logName()); - assertEquals(RESOURCE, PROTO_ENTRY.resource()); - assertEquals(TIMESTAMP, (long) PROTO_ENTRY.timestamp()); - assertEquals(SEVERITY, PROTO_ENTRY.severity()); - assertEquals(INSERT_ID, PROTO_ENTRY.insertId()); - assertEquals(HTTP_REQUEST, PROTO_ENTRY.httpRequest()); - assertEquals(LABELS, PROTO_ENTRY.labels()); - assertEquals(OPERATION, PROTO_ENTRY.operation()); - assertEquals(PROTO_PAYLOAD, PROTO_ENTRY.payload()); + assertEquals(LOG_NAME, STRING_ENTRY.getLogName()); + assertEquals(RESOURCE, STRING_ENTRY.getResource()); + assertEquals(TIMESTAMP, (long) STRING_ENTRY.getTimestamp()); + assertEquals(SEVERITY, STRING_ENTRY.getSeverity()); + assertEquals(INSERT_ID, STRING_ENTRY.getInsertId()); + assertEquals(HTTP_REQUEST, STRING_ENTRY.getHttpRequest()); + assertEquals(LABELS, STRING_ENTRY.getLabels()); + assertEquals(OPERATION, STRING_ENTRY.getOperation()); + assertEquals(STRING_PAYLOAD, STRING_ENTRY.getPayload()); + assertEquals(LOG_NAME, JSON_ENTRY.getLogName()); + assertEquals(RESOURCE, JSON_ENTRY.getResource()); + assertEquals(TIMESTAMP, (long) JSON_ENTRY.getTimestamp()); + assertEquals(SEVERITY, JSON_ENTRY.getSeverity()); + assertEquals(INSERT_ID, JSON_ENTRY.getInsertId()); + assertEquals(HTTP_REQUEST, JSON_ENTRY.getHttpRequest()); + assertEquals(LABELS, JSON_ENTRY.getLabels()); + assertEquals(OPERATION, JSON_ENTRY.getOperation()); + assertEquals(JSON_PAYLOAD, JSON_ENTRY.getPayload()); + assertEquals(LOG_NAME, PROTO_ENTRY.getLogName()); + assertEquals(RESOURCE, PROTO_ENTRY.getResource()); + assertEquals(TIMESTAMP, (long) PROTO_ENTRY.getTimestamp()); + assertEquals(SEVERITY, PROTO_ENTRY.getSeverity()); + assertEquals(INSERT_ID, PROTO_ENTRY.getInsertId()); + assertEquals(HTTP_REQUEST, PROTO_ENTRY.getHttpRequest()); + assertEquals(LABELS, PROTO_ENTRY.getLabels()); + assertEquals(OPERATION, PROTO_ENTRY.getOperation()); + assertEquals(PROTO_PAYLOAD, PROTO_ENTRY.getPayload()); + LogEntry logEntry = LogEntry.newBuilder(STRING_PAYLOAD) + .setPayload(StringPayload.of("otherPayload")) + .setLogName(LOG_NAME) + .setResource(RESOURCE) + .setTimestamp(TIMESTAMP) + .setSeverity(SEVERITY) + .setInsertId(INSERT_ID) + .setHttpRequest(HTTP_REQUEST) + .addLabel("key1", "value1") + .addLabel("key2", "value2") + .setOperation(OPERATION) + .build(); + assertEquals(LOG_NAME, logEntry.getLogName()); + assertEquals(RESOURCE, logEntry.getResource()); + assertEquals(TIMESTAMP, (long) logEntry.getTimestamp()); + assertEquals(SEVERITY, logEntry.getSeverity()); + assertEquals(INSERT_ID, logEntry.getInsertId()); + assertEquals(HTTP_REQUEST, logEntry.getHttpRequest()); + assertEquals(LABELS, logEntry.getLabels()); + assertEquals(OPERATION, logEntry.getOperation()); + assertEquals(StringPayload.of("otherPayload"), logEntry.getPayload()); + } + + @Test + public void testBuilderDeprecated() { + assertEquals(LOG_NAME, DEPRECATED_STRING_ENTRY.logName()); + assertEquals(RESOURCE, DEPRECATED_STRING_ENTRY.resource()); + assertEquals(TIMESTAMP, (long) DEPRECATED_STRING_ENTRY.timestamp()); + assertEquals(SEVERITY, DEPRECATED_STRING_ENTRY.severity()); + assertEquals(INSERT_ID, DEPRECATED_STRING_ENTRY.insertId()); + assertEquals(HTTP_REQUEST, DEPRECATED_STRING_ENTRY.httpRequest()); + assertEquals(LABELS, DEPRECATED_STRING_ENTRY.labels()); + assertEquals(OPERATION, DEPRECATED_STRING_ENTRY.operation()); + assertEquals(STRING_PAYLOAD, DEPRECATED_STRING_ENTRY.payload()); + assertEquals(LOG_NAME, DEPRECATED_JSON_ENTRY.logName()); + assertEquals(RESOURCE, DEPRECATED_JSON_ENTRY.resource()); + assertEquals(TIMESTAMP, (long) DEPRECATED_JSON_ENTRY.timestamp()); + assertEquals(SEVERITY, DEPRECATED_JSON_ENTRY.severity()); + assertEquals(INSERT_ID, DEPRECATED_JSON_ENTRY.insertId()); + assertEquals(HTTP_REQUEST, DEPRECATED_JSON_ENTRY.httpRequest()); + assertEquals(LABELS, DEPRECATED_JSON_ENTRY.labels()); + assertEquals(OPERATION, DEPRECATED_JSON_ENTRY.operation()); + assertEquals(JSON_PAYLOAD, DEPRECATED_JSON_ENTRY.payload()); + assertEquals(LOG_NAME, DEPRECATED_PROTO_ENTRY.logName()); + assertEquals(RESOURCE, DEPRECATED_PROTO_ENTRY.resource()); + assertEquals(TIMESTAMP, (long) DEPRECATED_PROTO_ENTRY.timestamp()); + assertEquals(SEVERITY, DEPRECATED_PROTO_ENTRY.severity()); + assertEquals(INSERT_ID, DEPRECATED_PROTO_ENTRY.insertId()); + assertEquals(HTTP_REQUEST, DEPRECATED_PROTO_ENTRY.httpRequest()); + assertEquals(LABELS, DEPRECATED_PROTO_ENTRY.labels()); + assertEquals(OPERATION, DEPRECATED_PROTO_ENTRY.operation()); + assertEquals(PROTO_PAYLOAD, DEPRECATED_PROTO_ENTRY.payload()); LogEntry logEntry = LogEntry.builder(STRING_PAYLOAD) .payload(StringPayload.of("otherPayload")) .logName(LOG_NAME) @@ -163,41 +246,41 @@ public void testBuilder() { @Test public void testToBuilder() { compareLogEntry(STRING_ENTRY, STRING_ENTRY.toBuilder().build()); - HttpRequest request = HttpRequest.builder() - .requestMethod(HttpRequest.RequestMethod.POST) - .status(500) + HttpRequest request = HttpRequest.newBuilder() + .setRequestMethod(HttpRequest.RequestMethod.POST) + .setStatus(500) .build(); LogEntry logEntry = STRING_ENTRY.toBuilder() - .payload(StringPayload.of("otherPayload")) - .logName("otherLogName") - .resource(MonitoredResource.builder("global").build()) - .timestamp(43) - .severity(Severity.DEBUG) - .insertId("otherInsertId") - .httpRequest(request) + .setPayload(StringPayload.of("otherPayload")) + .setLogName("otherLogName") + .setResource(MonitoredResource.newBuilder("global").build()) + .setTimestamp(43) + .setSeverity(Severity.DEBUG) + .setInsertId("otherInsertId") + .setHttpRequest(request) .clearLabels() .addLabel("key", "value") - .operation(Operation.of("otherId", "otherProducer")) + .setOperation(Operation.of("otherId", "otherProducer")) .build(); - assertEquals("otherLogName", logEntry.logName()); - assertEquals(MonitoredResource.builder("global").build(), logEntry.resource()); - assertEquals(43, (long) logEntry.timestamp()); - assertEquals(Severity.DEBUG, logEntry.severity()); - assertEquals("otherInsertId", logEntry.insertId()); - assertEquals(request, logEntry.httpRequest()); - assertEquals(ImmutableMap.of("key", "value"), logEntry.labels()); - assertEquals(Operation.of("otherId", "otherProducer"), logEntry.operation()); - assertEquals(StringPayload.of("otherPayload"), logEntry.payload()); + assertEquals("otherLogName", logEntry.getLogName()); + assertEquals(MonitoredResource.newBuilder("global").build(), logEntry.getResource()); + assertEquals(43, (long) logEntry.getTimestamp()); + assertEquals(Severity.DEBUG, logEntry.getSeverity()); + assertEquals("otherInsertId", logEntry.getInsertId()); + assertEquals(request, logEntry.getHttpRequest()); + assertEquals(ImmutableMap.of("key", "value"), logEntry.getLabels()); + assertEquals(Operation.of("otherId", "otherProducer"), logEntry.getOperation()); + assertEquals(StringPayload.of("otherPayload"), logEntry.getPayload()); logEntry = logEntry.toBuilder() - .payload(STRING_PAYLOAD) - .logName(LOG_NAME) - .resource(RESOURCE) - .timestamp(TIMESTAMP) - .severity(SEVERITY) - .insertId(INSERT_ID) - .httpRequest(HTTP_REQUEST) - .labels(LABELS) - .operation(OPERATION) + .setPayload(STRING_PAYLOAD) + .setLogName(LOG_NAME) + .setResource(RESOURCE) + .setTimestamp(TIMESTAMP) + .setSeverity(SEVERITY) + .setInsertId(INSERT_ID) + .setHttpRequest(HTTP_REQUEST) + .setLabels(LABELS) + .setOperation(OPERATION) .build(); compareLogEntry(STRING_ENTRY, logEntry); } @@ -215,15 +298,15 @@ public void testToAndFromPb() { private void compareLogEntry(LogEntry expected, LogEntry value) { assertEquals(expected, value); - assertEquals(expected.logName(), value.logName()); - assertEquals(expected.resource(), value.resource()); - assertEquals(expected.timestamp(), value.timestamp()); - assertEquals(expected.severity(), value.severity()); - assertEquals(expected.insertId(), value.insertId()); - assertEquals(expected.httpRequest(), value.httpRequest()); - assertEquals(expected.labels(), value.labels()); - assertEquals(expected.operation(), value.operation()); - assertEquals(expected.payload(), value.payload()); + assertEquals(expected.getLogName(), value.getLogName()); + assertEquals(expected.getResource(), value.getResource()); + assertEquals(expected.getTimestamp(), value.getTimestamp()); + assertEquals(expected.getSeverity(), value.getSeverity()); + assertEquals(expected.getInsertId(), value.getInsertId()); + assertEquals(expected.getHttpRequest(), value.getHttpRequest()); + assertEquals(expected.getLabels(), value.getLabels()); + assertEquals(expected.getOperation(), value.getOperation()); + assertEquals(expected.getPayload(), value.getPayload()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingHandlerTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingHandlerTest.java index f8f1bf7a9bab..50282b59f760 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingHandlerTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingHandlerTest.java @@ -46,68 +46,68 @@ public class LoggingHandlerTest { private static final String PROJECT = "project"; private static final MonitoredResource DEFAULT_RESOURCE = MonitoredResource.of("global", ImmutableMap.of("project_id", PROJECT)); - private static final LogEntry FINEST_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.DEBUG) + private static final LogEntry FINEST_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.DEBUG) .addLabel("levelName", "FINEST") .addLabel("levelValue", String.valueOf(Level.FINEST.intValue())) .build(); - private static final LogEntry FINER_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.DEBUG) + private static final LogEntry FINER_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.DEBUG) .addLabel("levelName", "FINER") .addLabel("levelValue", String.valueOf(Level.FINER.intValue())) .build(); - private static final LogEntry FINE_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.DEBUG) + private static final LogEntry FINE_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.DEBUG) .addLabel("levelName", "FINE") .addLabel("levelValue", String.valueOf(Level.FINE.intValue())) .build(); - private static final LogEntry CONFIG_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.INFO) + private static final LogEntry CONFIG_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.INFO) .addLabel("levelName", "CONFIG") .addLabel("levelValue", String.valueOf(Level.CONFIG.intValue())) .build(); - private static final LogEntry INFO_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.INFO) + private static final LogEntry INFO_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.INFO) .addLabel("levelName", "INFO") .addLabel("levelValue", String.valueOf(Level.INFO.intValue())) .build(); - private static final LogEntry WARNING_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.WARNING) + private static final LogEntry WARNING_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.WARNING) .addLabel("levelName", "WARNING") .addLabel("levelValue", String.valueOf(Level.WARNING.intValue())) .build(); - private static final LogEntry SEVERE_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.ERROR) + private static final LogEntry SEVERE_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.ERROR) .addLabel("levelName", "SEVERE") .addLabel("levelValue", String.valueOf(Level.SEVERE.intValue())) .build(); - private static final LogEntry DEBUG_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.DEBUG) + private static final LogEntry DEBUG_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.DEBUG) .addLabel("levelName", "DEBUG") .addLabel("levelValue", String.valueOf(LoggingLevel.DEBUG.intValue())) .build(); - private static final LogEntry NOTICE_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.NOTICE) + private static final LogEntry NOTICE_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.NOTICE) .addLabel("levelName", "NOTICE") .addLabel("levelValue", String.valueOf(LoggingLevel.NOTICE.intValue())) .build(); - private static final LogEntry ERROR_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.ERROR) + private static final LogEntry ERROR_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.ERROR) .addLabel("levelName", "ERROR") .addLabel("levelValue", String.valueOf(LoggingLevel.ERROR.intValue())) .build(); - private static final LogEntry CRITICAL_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.CRITICAL) + private static final LogEntry CRITICAL_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.CRITICAL) .addLabel("levelName", "CRITICAL") .addLabel("levelValue", String.valueOf(LoggingLevel.CRITICAL.intValue())) .build(); - private static final LogEntry ALERT_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.ALERT) + private static final LogEntry ALERT_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.ALERT) .addLabel("levelName", "ALERT") .addLabel("levelValue", String.valueOf(LoggingLevel.ALERT.intValue())) .build(); - private static final LogEntry EMERGENCY_ENTRY = LogEntry.builder(StringPayload.of(MESSAGE)) - .severity(Severity.EMERGENCY) + private static final LogEntry EMERGENCY_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) + .setSeverity(Severity.EMERGENCY) .addLabel("levelName", "EMERGENCY") .addLabel("levelValue", String.valueOf(LoggingLevel.EMERGENCY.intValue())) .build(); diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java index 2c70ba2da03f..f55b21f27efc 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java @@ -89,8 +89,8 @@ public class LoggingImplTest { private static final String METRIC_NAME_PB = "projects/" + PROJECT + "/metrics/" + METRIC_NAME; private static final String FILTER = "logName=projects/my-projectid/logs/syslog"; private static final String DESCRIPTION = "description"; - private static final MetricInfo METRIC_INFO = MetricInfo.builder(METRIC_NAME, FILTER) - .description(DESCRIPTION) + private static final MetricInfo METRIC_INFO = MetricInfo.newBuilder(METRIC_NAME, FILTER) + .setDescription(DESCRIPTION) .build(); private static final com.google.api.MonitoredResourceDescriptor DESCRIPTOR_PB = com.google.api.MonitoredResourceDescriptor.getDefaultInstance(); @@ -99,14 +99,14 @@ public class LoggingImplTest { private static final String LOG_NAME = "log"; private static final String LOG_NAME_PB = "projects/" + PROJECT + "/logs/" + LOG_NAME; private static final MonitoredResource MONITORED_RESOURCE = - MonitoredResource.builder("global").addLabel("project-id", PROJECT).build(); - private static final LogEntry LOG_ENTRY1 = LogEntry.builder(StringPayload.of("entry1")) - .logName(LOG_NAME) - .resource(MONITORED_RESOURCE) + MonitoredResource.newBuilder("global").addLabel("project-id", PROJECT).build(); + private static final LogEntry LOG_ENTRY1 = LogEntry.newBuilder(StringPayload.of("entry1")) + .setLogName(LOG_NAME) + .setResource(MONITORED_RESOURCE) .build(); - private static final LogEntry LOG_ENTRY2 = LogEntry.builder(StringPayload.of("entry2")) - .logName(LOG_NAME) - .resource(MONITORED_RESOURCE) + private static final LogEntry LOG_ENTRY2 = LogEntry.newBuilder(StringPayload.of("entry2")) + .setLogName(LOG_NAME) + .setResource(MONITORED_RESOURCE) .build(); private static final Function SINK_TO_PB_FUNCTION = new Function() { diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingLevelTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingLevelTest.java index c2a93a7711f7..3c5ccee1884b 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingLevelTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingLevelTest.java @@ -29,6 +29,7 @@ public class LoggingLevelTest { public void testDebug() { LoggingLevel debug = LoggingLevel.DEBUG; assertEquals(Severity.DEBUG, debug.severity()); + assertEquals(Severity.DEBUG, debug.getSeverity()); assertEquals("DEBUG", debug.getName()); assertTrue(debug.intValue() < Level.FINEST.intValue()); assertTrue(debug.intValue() > Level.ALL.intValue()); @@ -38,6 +39,7 @@ public void testDebug() { public void testNotice() { LoggingLevel notice = LoggingLevel.NOTICE; assertEquals(Severity.NOTICE, notice.severity()); + assertEquals(Severity.NOTICE, notice.getSeverity()); assertEquals("NOTICE", notice.getName()); assertTrue(notice.intValue() > Level.INFO.intValue()); assertTrue(notice.intValue() < Level.WARNING.intValue()); @@ -47,6 +49,7 @@ public void testNotice() { public void testError() { LoggingLevel error = LoggingLevel.ERROR; assertEquals(Severity.ERROR, error.severity()); + assertEquals(Severity.ERROR, error.getSeverity()); assertEquals("ERROR", error.getName()); assertTrue(error.intValue() > Level.WARNING.intValue()); assertTrue(error.intValue() < Level.SEVERE.intValue()); @@ -56,6 +59,7 @@ public void testError() { public void testCritical() { LoggingLevel critical = LoggingLevel.CRITICAL; assertEquals(Severity.CRITICAL, critical.severity()); + assertEquals(Severity.CRITICAL, critical.getSeverity()); assertEquals("CRITICAL", critical.getName()); assertTrue(critical.intValue() > LoggingLevel.SEVERE.intValue()); assertTrue(critical.intValue() < Level.OFF.intValue()); @@ -65,6 +69,7 @@ public void testCritical() { public void testAlert() { LoggingLevel alert = LoggingLevel.ALERT; assertEquals(Severity.ALERT, alert.severity()); + assertEquals(Severity.ALERT, alert.getSeverity()); assertEquals("ALERT", alert.getName()); assertTrue(alert.intValue() > LoggingLevel.CRITICAL.intValue()); assertTrue(alert.intValue() < Level.OFF.intValue()); @@ -74,6 +79,7 @@ public void testAlert() { public void testEmergency() { LoggingLevel emergency = LoggingLevel.EMERGENCY; assertEquals(Severity.EMERGENCY, emergency.severity()); + assertEquals(Severity.EMERGENCY, emergency.getSeverity()); assertEquals("EMERGENCY", emergency.getName()); assertTrue(emergency.intValue() > LoggingLevel.ALERT.intValue()); assertTrue(emergency.intValue() < Level.OFF.intValue()); diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java index 5c05185ad268..495b067eb39d 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingTest.java @@ -44,46 +44,46 @@ public class LoggingTest { public void testListOption() { // page token ListOption listOption = ListOption.pageToken(PAGE_TOKEN); - assertEquals(PAGE_TOKEN, listOption.value()); - assertEquals(ListOption.OptionType.PAGE_TOKEN, listOption.optionType()); + assertEquals(PAGE_TOKEN, listOption.getValue()); + assertEquals(ListOption.OptionType.PAGE_TOKEN, listOption.getOptionType()); // page size listOption = ListOption.pageSize(PAGE_SIZE); - assertEquals(PAGE_SIZE, listOption.value()); - assertEquals(ListOption.OptionType.PAGE_SIZE, listOption.optionType()); + assertEquals(PAGE_SIZE, listOption.getValue()); + assertEquals(ListOption.OptionType.PAGE_SIZE, listOption.getOptionType()); } @Test public void testEntryListOption() { EntryListOption listOption = EntryListOption.pageToken(PAGE_TOKEN); - assertEquals(PAGE_TOKEN, listOption.value()); - assertEquals(EntryListOption.OptionType.PAGE_TOKEN, listOption.optionType()); + assertEquals(PAGE_TOKEN, listOption.getValue()); + assertEquals(EntryListOption.OptionType.PAGE_TOKEN, listOption.getOptionType()); // page size listOption = EntryListOption.pageSize(PAGE_SIZE); - assertEquals(PAGE_SIZE, listOption.value()); - assertEquals(EntryListOption.OptionType.PAGE_SIZE, listOption.optionType()); + assertEquals(PAGE_SIZE, listOption.getValue()); + assertEquals(EntryListOption.OptionType.PAGE_SIZE, listOption.getOptionType()); // filter listOption = EntryListOption.filter(FILTER); - assertEquals(FILTER, listOption.value()); - assertEquals(EntryListOption.OptionType.FILTER, listOption.optionType()); + assertEquals(FILTER, listOption.getValue()); + assertEquals(EntryListOption.OptionType.FILTER, listOption.getOptionType()); // sort order listOption = EntryListOption.sortOrder(SortingField.TIMESTAMP, SortingOrder.ASCENDING); - assertEquals("timestamp asc", listOption.value()); - assertEquals(EntryListOption.OptionType.ORDER_BY, listOption.optionType()); + assertEquals("timestamp asc", listOption.getValue()); + assertEquals(EntryListOption.OptionType.ORDER_BY, listOption.getOptionType()); listOption = EntryListOption.sortOrder(SortingField.TIMESTAMP, SortingOrder.DESCENDING); - assertEquals("timestamp desc", listOption.value()); - assertEquals(EntryListOption.OptionType.ORDER_BY, listOption.optionType()); + assertEquals("timestamp desc", listOption.getValue()); + assertEquals(EntryListOption.OptionType.ORDER_BY, listOption.getOptionType()); } @Test public void testWriteOption() { WriteOption writeOption = WriteOption.labels(LABELS); - assertEquals(LABELS, writeOption.value()); - assertEquals(WriteOption.OptionType.LABELS, writeOption.optionType()); + assertEquals(LABELS, writeOption.getValue()); + assertEquals(WriteOption.OptionType.LABELS, writeOption.getOptionType()); writeOption = WriteOption.logName(LOG_NAME); - assertEquals(LOG_NAME, writeOption.value()); - assertEquals(WriteOption.OptionType.LOG_NAME, writeOption.optionType()); + assertEquals(LOG_NAME, writeOption.getValue()); + assertEquals(WriteOption.OptionType.LOG_NAME, writeOption.getOptionType()); writeOption = WriteOption.resource(RESOURCE); - assertEquals(RESOURCE, writeOption.value()); - assertEquals(WriteOption.OptionType.RESOURCE, writeOption.optionType()); + assertEquals(RESOURCE, writeOption.getValue()); + assertEquals(WriteOption.OptionType.RESOURCE, writeOption.getOptionType()); } } diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/MetricInfoTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/MetricInfoTest.java index 5b4be469cbbb..8e1682dc1701 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/MetricInfoTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/MetricInfoTest.java @@ -29,29 +29,34 @@ public class MetricInfoTest { private static final String NEW_NAME = "newName"; private static final String NEW_FILTER = "logName=projects/my-projectid/logs/newSyslog"; private static final String NEW_DESCRIPTION = "newDescription"; - private static final MetricInfo METRIC_INFO = MetricInfo.builder(NAME, FILTER) + private static final MetricInfo METRIC_INFO = MetricInfo.newBuilder(NAME, FILTER) + .setDescription(DESCRIPTION) + .build(); + private static final MetricInfo DEPRECATED_METRIC_INFO = MetricInfo.builder(NAME, FILTER) .description(DESCRIPTION) .build(); @Test public void testOf() { MetricInfo metricInfo = MetricInfo.of(NAME, FILTER); - assertEquals(NAME, metricInfo.name()); - assertEquals(FILTER, metricInfo.filter()); - assertNull(metricInfo.description()); + assertEquals(NAME, metricInfo.getName()); + assertEquals(FILTER, metricInfo.getFilter()); + assertNull(metricInfo.getDescription()); } @Test public void testBuilder() { - assertEquals(NAME, METRIC_INFO.name()); - assertEquals(FILTER, METRIC_INFO.filter()); - assertEquals(DESCRIPTION, METRIC_INFO.description()); + assertEquals(NAME, METRIC_INFO.getName()); + assertEquals(FILTER, METRIC_INFO.getFilter()); + assertEquals(DESCRIPTION, METRIC_INFO.getDescription()); } @Test - public void testToBuilder() { - compareMetricInfo(METRIC_INFO, METRIC_INFO.toBuilder().build()); - MetricInfo metricInfo = METRIC_INFO.toBuilder() + public void testBuilderDeprecated() { + assertEquals(NAME, DEPRECATED_METRIC_INFO.getName()); + assertEquals(FILTER, DEPRECATED_METRIC_INFO.getFilter()); + assertEquals(DESCRIPTION, DEPRECATED_METRIC_INFO.getDescription()); + MetricInfo metricInfo = DEPRECATED_METRIC_INFO.toBuilder() .name(NEW_NAME) .description(NEW_DESCRIPTION) .filter(NEW_FILTER) @@ -59,10 +64,23 @@ public void testToBuilder() { assertEquals(NEW_NAME, metricInfo.name()); assertEquals(NEW_FILTER, metricInfo.filter()); assertEquals(NEW_DESCRIPTION, metricInfo.description()); + } + + @Test + public void testToBuilder() { + compareMetricInfo(METRIC_INFO, METRIC_INFO.toBuilder().build()); + MetricInfo metricInfo = METRIC_INFO.toBuilder() + .setName(NEW_NAME) + .setDescription(NEW_DESCRIPTION) + .setFilter(NEW_FILTER) + .build(); + assertEquals(NEW_NAME, metricInfo.getName()); + assertEquals(NEW_FILTER, metricInfo.getFilter()); + assertEquals(NEW_DESCRIPTION, metricInfo.getDescription()); metricInfo = metricInfo.toBuilder() - .name(NAME) - .description(DESCRIPTION) - .filter(FILTER) + .setName(NAME) + .setDescription(DESCRIPTION) + .setFilter(FILTER) .build(); compareMetricInfo(METRIC_INFO, metricInfo); } @@ -76,9 +94,9 @@ public void testToAndFromPb() { private void compareMetricInfo(MetricInfo expected, MetricInfo value) { assertEquals(expected, value); - assertEquals(expected.name(), value.name()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.filter(), value.filter()); + assertEquals(expected.getName(), value.getName()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getFilter(), value.getFilter()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/MetricTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/MetricTest.java index 839745ca7283..6f9b00edc23f 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/MetricTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/MetricTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import com.google.common.util.concurrent.Futures; @@ -41,8 +42,8 @@ public class MetricTest { private static final String NEW_NAME = "newName"; private static final String NEW_FILTER = "logName=projects/my-projectid/logs/newSyslog"; private static final String NEW_DESCRIPTION = "newDescription"; - private static final MetricInfo METRIC_INFO = MetricInfo.builder(NAME, FILTER) - .description(DESCRIPTION) + private static final MetricInfo METRIC_INFO = MetricInfo.newBuilder(NAME, FILTER) + .setDescription(DESCRIPTION) .build(); private final Logging serviceMockReturnsOptions = createStrictMock(Logging.class); private final LoggingOptions mockOptions = createMock(LoggingOptions.class); @@ -70,7 +71,22 @@ public void tearDown() throws Exception { public void testBuilder() { initializeExpectedMetric(2); replay(logging); - MetricInfo builtMetric = expectedMetric.toBuilder() + Metric builtMetric = expectedMetric.toBuilder() + .setName(NEW_NAME) + .setFilter(NEW_FILTER) + .setDescription(NEW_DESCRIPTION) + .build(); + assertEquals(NEW_NAME, builtMetric.getName()); + assertEquals(NEW_DESCRIPTION, builtMetric.getDescription()); + assertEquals(NEW_FILTER, builtMetric.getFilter()); + assertSame(serviceMockReturnsOptions, builtMetric.getLogging()); + } + + @Test + public void testBuilderDeprecated() { + initializeExpectedMetric(2); + replay(logging); + Metric builtMetric = expectedMetric.toBuilder() .name(NEW_NAME) .filter(NEW_FILTER) .description(NEW_DESCRIPTION) @@ -78,6 +94,7 @@ public void testBuilder() { assertEquals(NEW_NAME, builtMetric.name()); assertEquals(NEW_DESCRIPTION, builtMetric.description()); assertEquals(NEW_FILTER, builtMetric.filter()); + assertSame(serviceMockReturnsOptions, builtMetric.logging()); } @Test @@ -90,7 +107,7 @@ public void testToBuilder() { @Test public void testReload() { initializeExpectedMetric(2); - MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build(); + MetricInfo updatedInfo = METRIC_INFO.toBuilder().setFilter(NEW_FILTER).build(); Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo)); expect(logging.options()).andReturn(mockOptions); @@ -114,7 +131,7 @@ public void testReloadNull() { @Test public void testReloadAsync() throws ExecutionException, InterruptedException { initializeExpectedMetric(2); - MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build(); + MetricInfo updatedInfo = METRIC_INFO.toBuilder().setFilter(NEW_FILTER).build(); Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo)); expect(logging.options()).andReturn(mockOptions); expect(logging.getMetricAsync(NAME)) @@ -138,28 +155,28 @@ public void testReloadAsyncNull() throws ExecutionException, InterruptedExceptio @Test public void testUpdate() { initializeExpectedMetric(2); - MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build(); + MetricInfo updatedInfo = METRIC_INFO.toBuilder().setFilter(NEW_FILTER).build(); Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo)); expect(logging.options()).andReturn(mockOptions).times(2); expect(logging.update(expectedMetric)).andReturn(expectedMetric); replay(logging); initializeMetric(); - Metric updatedMetric = metric.toBuilder().filter(NEW_FILTER).build().update(); + Metric updatedMetric = metric.toBuilder().setFilter(NEW_FILTER).build().update(); compareMetric(expectedMetric, updatedMetric); } @Test public void testUpdateAsync() throws ExecutionException, InterruptedException { initializeExpectedMetric(2); - MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build(); + MetricInfo updatedInfo = METRIC_INFO.toBuilder().setFilter(NEW_FILTER).build(); Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo)); expect(logging.options()).andReturn(mockOptions).times(2); expect(logging.updateAsync(expectedMetric)).andReturn(Futures.immediateFuture(expectedMetric)); replay(logging); initializeMetric(); - Metric updatedMetric = metric.toBuilder().filter(NEW_FILTER).build().updateAsync().get(); + Metric updatedMetric = metric.toBuilder().setFilter(NEW_FILTER).build().updateAsync().get(); compareMetric(expectedMetric, updatedMetric); } @@ -205,9 +222,9 @@ public void testDeleteAsyncFalse() throws ExecutionException, InterruptedExcepti private void compareMetric(Metric expected, Metric value) { assertEquals(expected, value); - assertEquals(expected.name(), value.name()); - assertEquals(expected.description(), value.description()); - assertEquals(expected.filter(), value.filter()); + assertEquals(expected.getName(), value.getName()); + assertEquals(expected.getDescription(), value.getDescription()); + assertEquals(expected.getFilter(), value.getFilter()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/OperationTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/OperationTest.java index 9de7d6fa61c9..1b7601379b05 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/OperationTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/OperationTest.java @@ -28,23 +28,30 @@ public class OperationTest { private static final String PRODUCER = "producer"; private static final Boolean FIRST = true; private static final Boolean LAST = false; - private static final Operation OPERATION = Operation.builder(ID, PRODUCER) + private static final Operation OPERATION = Operation.newBuilder(ID, PRODUCER) + .setFirst(FIRST) + .setLast(LAST) + .build(); + private static final Operation DEPRECATED_OPERATION = Operation.builder(ID, PRODUCER) .first(FIRST) .last(LAST) .build(); @Test public void testBuilder() { - assertEquals(ID, OPERATION.id()); - assertEquals(PRODUCER, OPERATION.producer()); + assertEquals(ID, OPERATION.getId()); + assertEquals(PRODUCER, OPERATION.getProducer()); assertTrue(OPERATION.first()); assertFalse(OPERATION.last()); } @Test - public void testToBuilder() { - compareLogOperation(OPERATION, OPERATION.toBuilder().build()); - Operation operation = OPERATION.toBuilder() + public void testBuilderDeprecated() { + assertEquals(ID, DEPRECATED_OPERATION.id()); + assertEquals(PRODUCER, DEPRECATED_OPERATION.producer()); + assertTrue(DEPRECATED_OPERATION.first()); + assertFalse(DEPRECATED_OPERATION.last()); + Operation operation = DEPRECATED_OPERATION.toBuilder() .id("newId") .producer("newProducer") .first(false) @@ -54,11 +61,26 @@ public void testToBuilder() { assertEquals("newProducer", operation.producer()); assertFalse(operation.first()); assertTrue(operation.last()); + } + + @Test + public void testToBuilder() { + compareLogOperation(OPERATION, OPERATION.toBuilder().build()); + Operation operation = OPERATION.toBuilder() + .setId("newId") + .setProducer("newProducer") + .setFirst(false) + .setLast(true) + .build(); + assertEquals("newId", operation.getId()); + assertEquals("newProducer", operation.getProducer()); + assertFalse(operation.first()); + assertTrue(operation.last()); operation = operation.toBuilder() - .id(ID) - .producer(PRODUCER) - .first(FIRST) - .last(LAST) + .setId(ID) + .setProducer(PRODUCER) + .setFirst(FIRST) + .setLast(LAST) .build(); compareLogOperation(OPERATION, operation); } @@ -66,8 +88,8 @@ public void testToBuilder() { @Test public void testOf() { Operation operation = Operation.of(ID, PRODUCER); - assertEquals(ID, operation.id()); - assertEquals(PRODUCER, operation.producer()); + assertEquals(ID, operation.getId()); + assertEquals(PRODUCER, operation.getProducer()); assertFalse(operation.first()); assertFalse(operation.last()); } @@ -81,8 +103,8 @@ public void testToAndFromPb() { private void compareLogOperation(Operation expected, Operation value) { assertEquals(expected, value); - assertEquals(expected.id(), value.id()); - assertEquals(expected.producer(), value.producer()); + assertEquals(expected.getId(), value.getId()); + assertEquals(expected.getProducer(), value.getProducer()); assertEquals(expected.first(), value.first()); assertEquals(expected.last(), value.last()); assertEquals(expected.hashCode(), value.hashCode()); diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/OptionTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/OptionTest.java index 536a9f6d4ef4..274c41bb345f 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/OptionTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/OptionTest.java @@ -55,11 +55,11 @@ public void testHashCode() { @Test public void testConstructor() { - assertEquals(OPTION_TYPE, OPTION.optionType()); - assertEquals(VALUE, OPTION.value()); + assertEquals(OPTION_TYPE, OPTION.getOptionType()); + assertEquals(VALUE, OPTION.getValue()); Option option = new Option(OPTION_TYPE, null) {}; - assertEquals(OPTION_TYPE, option.optionType()); - assertNull(option.value()); + assertEquals(OPTION_TYPE, option.getOptionType()); + assertNull(option.getValue()); thrown.expect(NullPointerException.class); new Option(null, VALUE) {}; } @@ -67,10 +67,10 @@ public void testConstructor() { @Test public void testListOption() { Option option = ListOption.pageSize(42); - assertEquals(ListOption.OptionType.PAGE_SIZE, option.optionType()); - assertEquals(42, option.value()); + assertEquals(ListOption.OptionType.PAGE_SIZE, option.getOptionType()); + assertEquals(42, option.getValue()); option = ListOption.pageToken("cursor"); - assertEquals(ListOption.OptionType.PAGE_TOKEN, option.optionType()); - assertEquals("cursor", option.value()); + assertEquals(ListOption.OptionType.PAGE_TOKEN, option.getOptionType()); + assertEquals("cursor", option.getValue()); } } diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/PayloadTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/PayloadTest.java index d2e4705a6441..bc77fc3df0bc 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/PayloadTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/PayloadTest.java @@ -96,6 +96,21 @@ public class PayloadTest { @Test public void testOf() { + assertEquals(Type.STRING, STRING_PAYLOAD.getType()); + assertEquals(STRING_DATA, STRING_PAYLOAD.getData()); + assertEquals(Type.JSON, JSON_PAYLOAD.getType()); + assertEquals(STRUCT_DATA, JSON_PAYLOAD.getData()); + assertEquals(JSON_DATA, JSON_PAYLOAD.getDataAsMap()); + assertEquals(Type.PROTO, PROTO_PAYLOAD.getType()); + assertEquals(PROTO_DATA, PROTO_PAYLOAD.getData()); + JsonPayload jsonPayload = JsonPayload.of(STRUCT_DATA); + assertEquals(Type.JSON, jsonPayload.getType()); + assertEquals(STRUCT_DATA, jsonPayload.getData()); + assertEquals(JSON_DATA, jsonPayload.getDataAsMap()); + } + + @Test + public void testOfDeprecated() { assertEquals(Type.STRING, STRING_PAYLOAD.type()); assertEquals(STRING_DATA, STRING_PAYLOAD.data()); assertEquals(Type.JSON, JSON_PAYLOAD.type()); @@ -124,8 +139,8 @@ public void testToAndFromPb() { private void comparePayload(Payload expected, Payload value) { assertEquals(expected, value); - assertEquals(expected.type(), value.type()); - assertEquals(expected.data(), value.data()); + assertEquals(expected.getType(), value.getType()); + assertEquals(expected.getData(), value.getData()); assertEquals(expected.hashCode(), value.hashCode()); } } diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/SerializationTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/SerializationTest.java index 2cd728c8f910..ca172c933506 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/SerializationTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/SerializationTest.java @@ -44,9 +44,9 @@ public class SerializationTest extends BaseSerializationTest { .authCredentials(AuthCredentials.noAuth()) .host("localhost") .build().service(); - private static final HttpRequest HTTP_REQUEST = HttpRequest.builder() - .requestMethod(HttpRequest.RequestMethod.GET) - .status(404) + private static final HttpRequest HTTP_REQUEST = HttpRequest.newBuilder() + .setRequestMethod(HttpRequest.RequestMethod.GET) + .setStatus(404) .build(); private static final Operation OPERATION = Operation.of("id", "producer"); private static final StringPayload STRING_PAYLOAD = StringPayload.of("payload"); diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java index e22b2259e82f..265f52d428d1 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java @@ -40,30 +40,61 @@ public class SinkInfoTest { DatasetDestination.of("project", "dataset"); private static final TopicDestination TOPIC_DESTINATION = TopicDestination.of("project", "topic"); - private static final SinkInfo BUCKET_SINK_INFO = SinkInfo.builder(NAME, BUCKET_DESTINATION) - .filter(FILTER) - .versionFormat(VERSION) + private static final SinkInfo BUCKET_SINK_INFO = SinkInfo.newBuilder(NAME, BUCKET_DESTINATION) + .setFilter(FILTER) + .setVersionFormat(VERSION) .build(); - private static final SinkInfo DATASET_SINK_INFO = SinkInfo.builder(NAME, DATASET_DESTINATION) - .filter(FILTER) - .versionFormat(VERSION) + private static final SinkInfo DATASET_SINK_INFO = SinkInfo.newBuilder(NAME, DATASET_DESTINATION) + .setFilter(FILTER) + .setVersionFormat(VERSION) .build(); - private static final SinkInfo TOPIC_SINK_INFO = SinkInfo.builder(NAME, TOPIC_DESTINATION) - .filter(FILTER) - .versionFormat(VERSION) + private static final SinkInfo TOPIC_SINK_INFO = SinkInfo.newBuilder(NAME, TOPIC_DESTINATION) + .setFilter(FILTER) + .setVersionFormat(VERSION) .build(); + private static final SinkInfo DEPRECATED_BUCKET_SINK_INFO = + SinkInfo.builder(NAME, BUCKET_DESTINATION) + .filter(FILTER) + .versionFormat(VERSION) + .build(); + private static final SinkInfo DEPRECATED_DATASET_SINK_INFO = + SinkInfo.builder(NAME, DATASET_DESTINATION) + .filter(FILTER) + .versionFormat(VERSION) + .build(); + private static final SinkInfo DEPRECATED_TOPIC_SINK_INFO = + SinkInfo.builder(NAME, TOPIC_DESTINATION) + .filter(FILTER) + .versionFormat(VERSION) + .build(); @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void testOfBucketDestination() { + assertEquals(Destination.Type.BUCKET, BUCKET_DESTINATION.getType()); + assertEquals("bucket", BUCKET_DESTINATION.getBucket()); + } + + @Test + public void testOfBucketDestinationDeprecated() { assertEquals(Destination.Type.BUCKET, BUCKET_DESTINATION.type()); assertEquals("bucket", BUCKET_DESTINATION.bucket()); } @Test public void testOfDatasetDestination() { + assertEquals(Destination.Type.DATASET, DATASET_DESTINATION.getType()); + assertEquals("project", DATASET_DESTINATION.getProject()); + assertEquals("dataset", DATASET_DESTINATION.getDataset()); + DatasetDestination datasetDestination = DatasetDestination.of("dataset"); + assertNull(datasetDestination.getProject()); + assertEquals("dataset", datasetDestination.getDataset()); + } + + @Test + public void testOfDatasetDestinationDeprecated() { assertEquals(Destination.Type.DATASET, DATASET_DESTINATION.type()); assertEquals("project", DATASET_DESTINATION.project()); assertEquals("dataset", DATASET_DESTINATION.dataset()); @@ -74,6 +105,16 @@ public void testOfDatasetDestination() { @Test public void testOfTopicDestination() { + assertEquals(Destination.Type.TOPIC, TOPIC_DESTINATION.getType()); + assertEquals("project", TOPIC_DESTINATION.getProject()); + assertEquals("topic", TOPIC_DESTINATION.getTopic()); + TopicDestination topicDestination = TopicDestination.of("topic"); + assertNull(topicDestination.getProject()); + assertEquals("topic", topicDestination.getTopic()); + } + + @Test + public void testOfTopicDestinationDeprecated() { assertEquals(Destination.Type.TOPIC, TOPIC_DESTINATION.type()); assertEquals("project", TOPIC_DESTINATION.project()); assertEquals("topic", TOPIC_DESTINATION.topic()); @@ -85,18 +126,18 @@ public void testOfTopicDestination() { @Test public void testToAndFromPbDestination() { BucketDestination bucketDestination = Destination.fromPb(BUCKET_DESTINATION.toPb("other")); - assertEquals(Destination.Type.BUCKET, bucketDestination.type()); - assertEquals("bucket", bucketDestination.bucket()); + assertEquals(Destination.Type.BUCKET, bucketDestination.getType()); + assertEquals("bucket", bucketDestination.getBucket()); compareBucketDestination(BUCKET_DESTINATION, bucketDestination); DatasetDestination datasetDestination = Destination.fromPb(DATASET_DESTINATION.toPb("other")); - assertEquals(Destination.Type.DATASET, datasetDestination.type()); - assertEquals("project", datasetDestination.project()); - assertEquals("dataset", datasetDestination.dataset()); + assertEquals(Destination.Type.DATASET, datasetDestination.getType()); + assertEquals("project", datasetDestination.getProject()); + assertEquals("dataset", datasetDestination.getDataset()); compareDatasetDestination(DATASET_DESTINATION, datasetDestination); TopicDestination topicDestination = Destination.fromPb(TOPIC_DESTINATION.toPb("other")); - assertEquals(Destination.Type.TOPIC, topicDestination.type()); - assertEquals("project", topicDestination.project()); - assertEquals("topic", topicDestination.topic()); + assertEquals(Destination.Type.TOPIC, topicDestination.getType()); + assertEquals("project", topicDestination.getProject()); + assertEquals("topic", topicDestination.getTopic()); compareTopicDestination(TOPIC_DESTINATION, topicDestination); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("wrongDestination is not a valid sink destination"); @@ -108,35 +149,44 @@ public void testToAndFromPbDestination_NoProjectId() { DatasetDestination datasetDestination = DatasetDestination.fromPb(DatasetDestination.of("dataset").toPb("project")); compareDatasetDestination(DATASET_DESTINATION, datasetDestination); - assertEquals("project", datasetDestination.project()); + assertEquals("project", datasetDestination.getProject()); TopicDestination topicDestination = TopicDestination.fromPb(TopicDestination.of("topic").toPb("project")); - assertEquals("project", topicDestination.project()); + assertEquals("project", topicDestination.getProject()); compareTopicDestination(TOPIC_DESTINATION, topicDestination); } @Test public void testBuilder() { - assertEquals(NAME, BUCKET_SINK_INFO.name()); - assertEquals(BUCKET_DESTINATION, BUCKET_SINK_INFO.destination()); - assertEquals(FILTER, BUCKET_SINK_INFO.filter()); - assertEquals(VERSION, BUCKET_SINK_INFO.versionFormat()); - assertEquals(NAME, DATASET_SINK_INFO.name()); - assertEquals(DATASET_DESTINATION, DATASET_SINK_INFO.destination()); - assertEquals(FILTER, DATASET_SINK_INFO.filter()); - assertEquals(VERSION, DATASET_SINK_INFO.versionFormat()); - assertEquals(NAME, TOPIC_SINK_INFO.name()); - assertEquals(TOPIC_DESTINATION, TOPIC_SINK_INFO.destination()); - assertEquals(FILTER, TOPIC_SINK_INFO.filter()); - assertEquals(VERSION, TOPIC_SINK_INFO.versionFormat()); + assertEquals(NAME, BUCKET_SINK_INFO.getName()); + assertEquals(BUCKET_DESTINATION, BUCKET_SINK_INFO.getDestination()); + assertEquals(FILTER, BUCKET_SINK_INFO.getFilter()); + assertEquals(VERSION, BUCKET_SINK_INFO.getVersionFormat()); + assertEquals(NAME, DATASET_SINK_INFO.getName()); + assertEquals(DATASET_DESTINATION, DATASET_SINK_INFO.getDestination()); + assertEquals(FILTER, DATASET_SINK_INFO.getFilter()); + assertEquals(VERSION, DATASET_SINK_INFO.getVersionFormat()); + assertEquals(NAME, TOPIC_SINK_INFO.getName()); + assertEquals(TOPIC_DESTINATION, TOPIC_SINK_INFO.getDestination()); + assertEquals(FILTER, TOPIC_SINK_INFO.getFilter()); + assertEquals(VERSION, TOPIC_SINK_INFO.getVersionFormat()); } @Test - public void testToBuilder() { - compareSinkInfo(BUCKET_SINK_INFO, BUCKET_SINK_INFO.toBuilder().build()); - compareSinkInfo(DATASET_SINK_INFO, DATASET_SINK_INFO.toBuilder().build()); - compareSinkInfo(TOPIC_SINK_INFO, TOPIC_SINK_INFO.toBuilder().build()); - SinkInfo updatedSinkInfo = BUCKET_SINK_INFO.toBuilder() + public void testBuilderDeprecated() { + assertEquals(NAME, DEPRECATED_BUCKET_SINK_INFO.name()); + assertEquals(BUCKET_DESTINATION, DEPRECATED_BUCKET_SINK_INFO.destination()); + assertEquals(FILTER, DEPRECATED_BUCKET_SINK_INFO.filter()); + assertEquals(VERSION, DEPRECATED_BUCKET_SINK_INFO.versionFormat()); + assertEquals(NAME, DEPRECATED_DATASET_SINK_INFO.name()); + assertEquals(DATASET_DESTINATION, DEPRECATED_DATASET_SINK_INFO.destination()); + assertEquals(FILTER, DEPRECATED_DATASET_SINK_INFO.filter()); + assertEquals(VERSION, DEPRECATED_DATASET_SINK_INFO.versionFormat()); + assertEquals(NAME, DEPRECATED_TOPIC_SINK_INFO.name()); + assertEquals(TOPIC_DESTINATION, DEPRECATED_TOPIC_SINK_INFO.destination()); + assertEquals(FILTER, DEPRECATED_TOPIC_SINK_INFO.filter()); + assertEquals(VERSION, DEPRECATED_TOPIC_SINK_INFO.versionFormat()); + SinkInfo updatedSinkInfo = DEPRECATED_BUCKET_SINK_INFO.toBuilder() .destination(TOPIC_DESTINATION) .name("newName") .filter("logName=projects/my-projectid/logs/syslog") @@ -146,11 +196,28 @@ public void testToBuilder() { assertEquals(TOPIC_DESTINATION, updatedSinkInfo.destination()); assertEquals("logName=projects/my-projectid/logs/syslog", updatedSinkInfo.filter()); assertEquals(VersionFormat.V2, updatedSinkInfo.versionFormat()); + } + + @Test + public void testToBuilder() { + compareSinkInfo(BUCKET_SINK_INFO, BUCKET_SINK_INFO.toBuilder().build()); + compareSinkInfo(DATASET_SINK_INFO, DATASET_SINK_INFO.toBuilder().build()); + compareSinkInfo(TOPIC_SINK_INFO, TOPIC_SINK_INFO.toBuilder().build()); + SinkInfo updatedSinkInfo = BUCKET_SINK_INFO.toBuilder() + .setDestination(TOPIC_DESTINATION) + .setName("newName") + .setFilter("logName=projects/my-projectid/logs/syslog") + .setVersionFormat(VersionFormat.V2) + .build(); + assertEquals("newName", updatedSinkInfo.getName()); + assertEquals(TOPIC_DESTINATION, updatedSinkInfo.getDestination()); + assertEquals("logName=projects/my-projectid/logs/syslog", updatedSinkInfo.getFilter()); + assertEquals(VersionFormat.V2, updatedSinkInfo.getVersionFormat()); updatedSinkInfo = BUCKET_SINK_INFO.toBuilder() - .destination(BUCKET_DESTINATION) - .name(NAME) - .filter(FILTER) - .versionFormat(VersionFormat.V1) + .setDestination(BUCKET_DESTINATION) + .setName(NAME) + .setFilter(FILTER) + .setVersionFormat(VersionFormat.V1) .build(); assertEquals(BUCKET_SINK_INFO, updatedSinkInfo); } @@ -182,33 +249,33 @@ public void testToAndFromPb_NoProjectId() { private void compareBucketDestination(BucketDestination expected, BucketDestination value) { assertEquals(expected, value); - assertEquals(expected.bucket(), value.bucket()); + assertEquals(expected.getBucket(), value.getBucket()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } private void compareDatasetDestination(DatasetDestination expected, DatasetDestination value) { assertEquals(expected, value); - assertEquals(expected.project(), value.project()); - assertEquals(expected.dataset(), value.dataset()); + assertEquals(expected.getProject(), value.getProject()); + assertEquals(expected.getDataset(), value.getDataset()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } private void compareTopicDestination(TopicDestination expected, TopicDestination value) { assertEquals(expected, value); - assertEquals(expected.project(), value.project()); - assertEquals(expected.topic(), value.topic()); + assertEquals(expected.getProject(), value.getProject()); + assertEquals(expected.getTopic(), value.getTopic()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } private void compareSinkInfo(SinkInfo expected, SinkInfo value) { assertEquals(expected, value); - assertEquals(expected.name(), value.name()); - assertEquals(expected.destination(), value.destination()); - assertEquals(expected.filter(), value.filter()); - assertEquals(expected.versionFormat(), value.versionFormat()); + assertEquals(expected.getName(), value.getName()); + assertEquals(expected.getDestination(), value.getDestination()); + assertEquals(expected.getFilter(), value.getFilter()); + assertEquals(expected.getVersionFormat(), value.getVersionFormat()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkTest.java index c7afe584d01f..de4325765ef5 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkTest.java @@ -48,9 +48,9 @@ public class SinkTest { private static final VersionFormat NEW_VERSION = VersionFormat.V2; private static final BucketDestination BUCKET_DESTINATION = BucketDestination.of("bucket"); private static final DatasetDestination DATASET_DESTINATION = DatasetDestination.of("dataset"); - private static final SinkInfo SINK_INFO = SinkInfo.builder(NAME, BUCKET_DESTINATION) - .filter(FILTER) - .versionFormat(VERSION) + private static final SinkInfo SINK_INFO = SinkInfo.newBuilder(NAME, BUCKET_DESTINATION) + .setFilter(FILTER) + .setVersionFormat(VERSION) .build(); private final Logging serviceMockReturnsOptions = createStrictMock(Logging.class); private final LoggingOptions mockOptions = createMock(LoggingOptions.class); @@ -78,7 +78,23 @@ public void tearDown() throws Exception { public void testBuilder() { initializeExpectedSink(2); replay(logging); - SinkInfo builtSink = expectedSink.toBuilder() + Sink builtSink = expectedSink.toBuilder() + .setName(NEW_NAME) + .setFilter(NEW_FILTER) + .setDestination(DATASET_DESTINATION) + .setVersionFormat(NEW_VERSION) + .build(); + assertEquals(NEW_NAME, builtSink.getName()); + assertEquals(DATASET_DESTINATION, builtSink.getDestination()); + assertEquals(NEW_FILTER, builtSink.getFilter()); + assertEquals(NEW_VERSION, builtSink.getVersionFormat()); + } + + @Test + public void testBuilderDeprecated() { + initializeExpectedSink(2); + replay(logging); + Sink builtSink = expectedSink.toBuilder() .name(NEW_NAME) .filter(NEW_FILTER) .destination(DATASET_DESTINATION) @@ -100,7 +116,7 @@ public void testToBuilder() { @Test public void testReload() { initializeExpectedSink(2); - SinkInfo updatedInfo = SINK_INFO.toBuilder().filter(NEW_FILTER).build(); + SinkInfo updatedInfo = SINK_INFO.toBuilder().setFilter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); expect(logging.options()).andReturn(mockOptions); @@ -124,7 +140,7 @@ public void testReloadNull() { @Test public void testReloadAsync() throws ExecutionException, InterruptedException { initializeExpectedSink(2); - SinkInfo updatedInfo = SINK_INFO.toBuilder().filter(NEW_FILTER).build(); + SinkInfo updatedInfo = SINK_INFO.toBuilder().setFilter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); expect(logging.options()).andReturn(mockOptions); expect(logging.getSinkAsync(NAME)) @@ -148,26 +164,26 @@ public void testReloadAsyncNull() throws ExecutionException, InterruptedExceptio @Test public void testUpdate() { initializeExpectedSink(2); - SinkInfo updatedInfo = SINK_INFO.toBuilder().filter(NEW_FILTER).build(); + SinkInfo updatedInfo = SINK_INFO.toBuilder().setFilter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); expect(logging.options()).andReturn(mockOptions).times(2); expect(logging.update(expectedSink)).andReturn(expectedSink); replay(logging); initializeSink(); - Sink updatedSink = sink.toBuilder().filter(NEW_FILTER).build().update(); + Sink updatedSink = sink.toBuilder().setFilter(NEW_FILTER).build().update(); compareSink(expectedSink, updatedSink); } @Test public void testUpdateAsync() throws ExecutionException, InterruptedException { initializeExpectedSink(2); - SinkInfo updatedInfo = SINK_INFO.toBuilder().filter(NEW_FILTER).build(); + SinkInfo updatedInfo = SINK_INFO.toBuilder().setFilter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); expect(logging.options()).andReturn(mockOptions).times(2); expect(logging.updateAsync(expectedSink)).andReturn(Futures.immediateFuture(expectedSink)); replay(logging); initializeSink(); - Sink updatedSink = sink.toBuilder().filter(NEW_FILTER).build().updateAsync().get(); + Sink updatedSink = sink.toBuilder().setFilter(NEW_FILTER).build().updateAsync().get(); compareSink(expectedSink, updatedSink); } @@ -213,10 +229,10 @@ public void testDeleteAsyncFalse() throws ExecutionException, InterruptedExcepti private void compareSink(Sink expected, Sink value) { assertEquals(expected, value); - assertEquals(expected.name(), value.name()); - assertEquals(expected.destination(), value.destination()); - assertEquals(expected.filter(), value.filter()); - assertEquals(expected.versionFormat(), value.versionFormat()); + assertEquals(expected.getName(), value.getName()); + assertEquals(expected.getDestination(), value.getDestination()); + assertEquals(expected.getFilter(), value.getFilter()); + assertEquals(expected.getVersionFormat(), value.getVersionFormat()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/StructsTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/StructsTest.java index 7b6a0df4e612..34b5bb5a9c34 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/StructsTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/StructsTest.java @@ -100,7 +100,7 @@ private void checkMapField(Map map, String key, T expected) { } private void checkStructField(Struct struct, String key, Value expected) { - Map map = struct.getFields(); + Map map = struct.getFieldsMap(); checkMapField(map, key, expected); } @@ -158,7 +158,7 @@ public void testNewStruct() { @Test public void testNewStructEmpty() { Struct struct = Structs.newStruct(EMPTY_MAP); - assertTrue(struct.getFields().isEmpty()); + assertTrue(struct.getFieldsMap().isEmpty()); } @Test diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITLoggingTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITLoggingTest.java index e4e70c7cc7ca..f3df67838816 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITLoggingTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITLoggingTest.java @@ -35,7 +35,7 @@ public class ITLoggingTest extends BaseSystemTest { @BeforeClass public static void beforeClass() { RemoteLoggingHelper helper = RemoteLoggingHelper.create(); - logging = helper.options().service(); + logging = helper.getOptions().service(); } @AfterClass