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..e7e1f9f7e442 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,21 +66,43 @@ 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) { this.type = type; return this; } + /** + * 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; + } + /** * 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}. */ + @Deprecated public Builder labels(Map labels) { this.labels = new HashMap<>(checkNotNull(labels)); return this; } + /** + * 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; + } + /** * Adds a label to the labels of the monitored resource. */ @@ -112,19 +134,39 @@ 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 type; } + /** + * 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; + } + /** * 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}. */ + @Deprecated public Map labels() { return labels; } + /** + * 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; + } + @Override public int hashCode() { return Objects.hash(type, labels); @@ -167,18 +209,26 @@ public Builder toBuilder() { /** * Returns a builder for {@code MonitoredResource} objects given the resource's type. */ + @Deprecated public static Builder builder(String type) { return new Builder(type); } + /** + * Returns a builder for {@code MonitoredResource} objects given the resource's type. + */ + public static Builder newBuilder(String type) { + return new Builder(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..012b5c49cd0c 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,25 +120,50 @@ static ValueType fromPb(com.google.api.LabelDescriptor.ValueType typePb) { /** * Returns the key associated to this label. */ + @Deprecated public String key() { return key; } + /** + * 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 valueType; } + /** + * Returns the type of data that can be assigned to this label. + */ + public ValueType getValueType() { + return valueType; + } + /** * Returns the optional human-readable description for this label. If not set, this method * returns {@code null}. */ + @Deprecated public String description() { return description; } + /** + * Returns the optional human-readable description for this label. If not set, this method + * returns {@code null}. + */ + public String getDescription() { + return description; + } + @Override public final int hashCode() { return Objects.hash(key, valueType, 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,44 +261,91 @@ 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 type; } + /** + * Returns the monitored resource type. For example, the type {@code cloudsql_database} represents + * databases in Google Cloud SQL. + */ + public String getType() { + return type; + } + /** * Returns an optional name for the monitored resource descriptor. If not set, this method returns * {@code null}. */ + @Deprecated public String name() { return name; } + /** + * Returns an optional name for the monitored resource descriptor. If not set, this method returns + * {@code null}. + */ + public String getName() { + return name; + } + /** * 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}. */ + @Deprecated public String displayName() { return displayName; } + /** + * 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; + } + /** * 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 description; } + /** + * 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; + } + /** * 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}. */ + @Deprecated public List labels() { return labels; } + /** + * 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; + } + @Override public final int hashCode() { return Objects.hash(type, name, displayName, description, 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-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..5bb53b85a660 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,121 +97,252 @@ public static final class Builder { /** * Sets the HTTP request method. */ + @Deprecated public Builder requestMethod(RequestMethod requestMethod) { this.requestMethod = requestMethod; return this; } + /** + * Sets the HTTP request method. + */ + public Builder setRequestMethod(RequestMethod requestMethod) { + this.requestMethod = requestMethod; + return this; + } + /** * 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}. */ + @Deprecated public Builder requestUrl(String requestUrl) { this.requestUrl = requestUrl; return this; } + /** + * 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; + } + /** * Sets the size of the HTTP request message in bytes, including the request headers and the * request body. */ + @Deprecated public Builder requestSize(long requestSize) { this.requestSize = requestSize; return this; } + /** + * 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; + } + /** * Sets the response code indicating the status of response. */ + @Deprecated public Builder status(int status) { this.status = status; return this; } + /** + * Sets the response code indicating the status of response. + */ + public Builder setStatus(int status) { + this.status = status; + return this; + } + /** * 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) { this.responseSize = responseSize; return this; } + /** + * 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; + } + /** * 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) { this.userAgent = userAgent; return this; } + /** + * 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; + } + /** * 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) { this.remoteIp = remoteIp; return this; } + /** + * 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; + } + /** * 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) { this.serverIp = serverIp; return this; } + /** + * 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; + } + /** * Sets the referer URL of the request, as defined in HTTP/1.1 Header Field Definitions. * * @see HTTP/1.1 Header Field * Definitions */ + @Deprecated public Builder referer(String referer) { this.referer = referer; return this; } + /** + * 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; + } + /** * Sets whether or not a cache lookup was attempted. If not set, {@code false} is used. */ + @Deprecated public Builder cacheLookup(boolean cacheLookup) { this.cacheLookup = cacheLookup; return this; } + /** + * 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; + } + /** * 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) { this.cacheHit = cacheHit; return this; } + /** + * 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; + } + /** * 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. */ + @Deprecated public Builder cacheValidatedWithOriginServer(boolean cacheValidatedWithOriginServer) { this.cacheValidatedWithOriginServer = cacheValidatedWithOriginServer; return this; } + /** + * 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; + } + /** * Sets the number of HTTP response bytes inserted into cache. Set only when a cache fill was * attempted. */ + @Deprecated public Builder cacheFillBytes(long cacheFillBytes) { this.cacheFillBytes = cacheFillBytes; return this; } + /** + * 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; + } + /** * Creates a {@code HttpRequest} object for this builder. */ @@ -239,76 +370,158 @@ public HttpRequest build() { /** * Returns the HTTP request method. */ + @Deprecated public RequestMethod requestMethod() { return requestMethod; } + /** + * Returns the HTTP request method. + */ + public RequestMethod getRequestMethod() { + return requestMethod; + } + /** * 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}. */ + @Deprecated public String requestUrl() { return requestUrl; } + /** + * 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; + } + /** * Returns the size of the HTTP request message in bytes, including the request headers and the * request body. */ + @Deprecated public Long requestSize() { return requestSize; } + /** + * 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 status; } + /** + * Returns the response code indicating the status of response. + */ + public Integer getStatus() { + return 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 responseSize; } + /** + * 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; + } + /** * 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 userAgent; } + /** + * 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; + } + /** * 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 remoteIp; } + /** + * 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; + } + /** * 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 serverIp; } + /** + * 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; + } + /** * Returns the referer URL of the request, as defined in HTTP/1.1 Header Field Definitions. * * @see HTTP/1.1 Header Field * Definitions */ + @Deprecated public String referer() { return referer; } + /** + * 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; + } + /** * Returns whether or not a cache lookup was attempted. If not set, this method returns * {@code false}. @@ -338,10 +551,19 @@ 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 cacheFillBytes; } + /** + * Returns the number of HTTP response bytes inserted into cache. Set only when a cache fill was + * attempted. + */ + public Long getCacheFillBytes() { + return cacheFillBytes; + } + @Override public int hashCode() { return Objects.hash(requestMethod, requestUrl, requestSize, status, responseSize, userAgent, @@ -423,7 +645,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 +663,52 @@ com.google.logging.type.HttpRequest toPb() { /** * Returns a builder for {@code HttpRequest} objects. */ + @Deprecated public static Builder builder() { return new Builder(); } + /** + * 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..6d8dcab75e31 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,65 +102,138 @@ 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) { this.logName = logName; return this; } + /** + * 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; + } + /** * 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. */ + @Deprecated public Builder resource(MonitoredResource resource) { this.resource = resource; return this; } + /** + * 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; + } + /** * 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) { this.timestamp = timestamp; return this; } + /** + * 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; + } + /** * Sets the severity of the log entry. If not set, {@link Severity#DEFAULT} is used. */ + @Deprecated public Builder severity(Severity severity) { this.severity = severity; return this; } + /** + * 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; + } + /** * 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. */ + @Deprecated public Builder insertId(String insertId) { this.insertId = insertId; return this; } + /** + * 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; + } + /** * Sets information about the HTTP request associated with this log entry, if applicable. */ + @Deprecated public Builder httpRequest(HttpRequest httpRequest) { this.httpRequest = httpRequest; return this; } + /** + * Sets information about the HTTP request associated with this log entry, if applicable. + */ + public Builder setHttpRequest(HttpRequest httpRequest) { + this.httpRequest = httpRequest; + return this; + } + /** * Sets an optional set of user-defined (key, value) data that provides additional information * about the log entry. */ + @Deprecated public Builder labels(Map labels) { this.labels = new HashMap<>(checkNotNull(labels)); return this; } + /** + * 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; + } + /** * Adds a label to the log entry's labels. Labels are user-defined (key, value) data that * provides additional information about the log entry. @@ -182,11 +255,20 @@ public Builder clearLabels() { /** * Sets information about an operation associated with the log entry, if applicable. */ + @Deprecated public Builder operation(Operation operation) { this.operation = operation; return this; } + /** + * Sets information about an operation associated with the log entry, if applicable. + */ + public Builder setOperation(Operation operation) { + this.operation = operation; + return this; + } + /** * 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 @@ -194,11 +276,24 @@ public Builder operation(Operation operation) { * * @see Log Entries and Logs */ + @Deprecated public Builder payload(Payload payload) { this.payload = payload; return this; } + /** + * 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; + } + /** * Creates a {@code LogEntry} object for this builder. */ @@ -226,64 +321,137 @@ 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 logName; } + /** + * 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; + } + /** * 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. */ + @Deprecated public MonitoredResource resource() { return resource; } + /** + * 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; + } + /** * 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 timestamp; } + /** + * 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 severity; } + /** + * Returns the severity of the log entry. If not set, {@link Severity#DEFAULT} is used. + */ + public Severity getSeverity() { + return 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 insertId; } + /** + * 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 httpRequest; } + /** + * Returns information about the HTTP request associated with this log entry, if applicable. + */ + public HttpRequest getHttpRequest() { + return httpRequest; + } + /** * Returns an optional set of user-defined (key, value) data that provides additional information * about the log entry. */ + @Deprecated public Map labels() { return labels; } + /** + * 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 operation; } + /** + * Returns information about an operation associated with the log entry, if applicable. + */ + public Operation getOperation() { + return operation; + } + /** * 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 @@ -292,10 +460,23 @@ public Operation operation() { * @see Log Entries and Logs */ @SuppressWarnings("unchecked") + @Deprecated public T payload() { return (T) payload; } + /** + * 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; + } + @Override public int hashCode() { return Objects.hash(logName, resource, timestamp, severity, insertId, httpRequest, labels, @@ -377,15 +558,23 @@ 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 new Builder(payload); } + /** + * Returns a builder for {@code LogEntry} objects given the entry payload. + */ + public static Builder newBuilder(Payload payload) { + return new Builder(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 +582,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/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..2c0a24c9673f 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 severity; } + + /** + * 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..22d09a6cdd66 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,41 @@ private Builder(Metric metric) { } @Override + @Deprecated public Builder name(String name) { - delegate.name(name); + delegate.setName(name); return this; } @Override + public Builder setName(String name) { + delegate.setName(name); + return this; + } + + @Override + @Deprecated public Builder description(String description) { - delegate.description(description); + delegate.setDescription(description); return this; } @Override + public Builder setDescription(String description) { + delegate.setDescription(description); + return this; + } + + @Override + @Deprecated public Builder filter(String filter) { - delegate.filter(filter); + delegate.setFilter(filter); + return this; + } + + @Override + public Builder setFilter(String filter) { + delegate.setFilter(filter); return this; } @@ -112,10 +133,18 @@ public final boolean equals(Object obj) { /** * Returns the metrics's {@code Logging} object used to issue requests. */ + @Deprecated public Logging logging() { return logging; } + /** + * Returns the metrics's {@code Logging} object used to issue requests. + */ + public Logging getLogging() { + return logging; + } + /** * Deletes this metric. * @@ -133,7 +162,7 @@ public Logging logging() { * @throws LoggingException upon failure */ public boolean delete() { - return logging.deleteMetric(name()); + return logging.deleteMetric(getName()); } /** @@ -156,7 +185,7 @@ public boolean delete() { * @throws LoggingException upon failure */ public Future deleteAsync() { - return logging.deleteMetricAsync(name()); + return logging.deleteMetricAsync(getName()); } /** @@ -174,7 +203,7 @@ public Future deleteAsync() { * @throws LoggingException upon failure */ public Metric reload() { - return logging.getMetric(name()); + return logging.getMetric(getName()); } /** @@ -195,7 +224,7 @@ public Metric reload() { * @throws LoggingException upon failure */ public Future reloadAsync() { - return logging.getMetricAsync(name()); + return logging.getMetricAsync(getName()); } /** 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..5813633f692e 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,23 +117,44 @@ static final class BuilderImpl extends Builder { } @Override + @Deprecated public Builder name(String name) { this.name = name; return this; } @Override + public Builder setName(String name) { + this.name = name; + return this; + } + + @Override + @Deprecated public Builder description(String description) { this.description = description; return this; } @Override + public Builder setDescription(String description) { + this.description = description; + return this; + } + + @Override + @Deprecated public Builder filter(String filter) { this.filter = filter; return this; } + @Override + public Builder setFilter(String filter) { + this.filter = filter; + return this; + } + @Override public MetricInfo build() { return new MetricInfo(this); @@ -127,17 +174,37 @@ 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 name; } + /** + * 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 description; } + /** + * Returns an optional description for this metric. Used for documentation purpose. + */ + public String getDescription() { + return description; + } + /** * Returns an advanced logs filter. The value of the metric is the number of log entries that * match this filter. Example: @@ -146,10 +213,23 @@ public String description() { * @see Advanced Log * Filters */ + @Deprecated public String filter() { return filter; } + /** + * 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; + } + @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -191,10 +271,18 @@ 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 new BuilderImpl(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); + } + /** * Creates a {@code MetricInfo} object given the name of the metric and its filter. */ @@ -213,9 +301,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..33a0f804b8b2 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,39 +67,80 @@ 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) { this.id = id; return this; } + /** + * 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; + } + /** * 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}. */ + @Deprecated public Builder producer(String producer) { this.producer = producer; return this; } + /** + * 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; + } + /** * 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) { this.first = first; return this; } + /** + * 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; + } + /** * 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) { this.last = last; return this; } + /** + * 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; + } + /** * Creates an {@code Operation} object for this builder. */ @@ -120,19 +161,39 @@ public Operation build() { * of the same operation. The combination of this value and {@link #producer()} must be globally * unique. */ + @Deprecated public String id() { return id; } + /** + * 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; + } + /** * 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}. */ + @Deprecated public String producer() { return producer; } + /** + * 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; + } + /** * Returns {@code true} if the corresponding entry is the first log entry in the operation, * {@code false} otherwise. @@ -199,22 +260,31 @@ 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 new Builder(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); + } + /** * Returns a {@code Operation} object given the operation and producer identifiers. The * 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..0884629968de 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 Structs.asMap(getData()); + } + + /** + * 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,17 +192,34 @@ 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 type; } + /** + * 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 data; } + /** + * Returns the log entry payload's data. + */ + public T getData() { + return data; + } + @Override public final boolean equals(Object obj) { if (obj == this) { 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..291aea6d022f 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,54 @@ private Builder(Sink sink) { } @Override + @Deprecated public Builder name(String name) { - delegate.name(name); + delegate.setName(name); return this; } @Override + public Builder setName(String name) { + delegate.setName(name); + return this; + } + + @Override + @Deprecated public Builder destination(Destination destination) { - delegate.destination(destination); + delegate.setDestination(destination); return this; } @Override + public Builder setDestination(Destination destination) { + delegate.setDestination(destination); + return this; + } + + @Override + @Deprecated public Builder filter(String filter) { - delegate.filter(filter); + delegate.setFilter(filter); + return this; + } + + @Override + public Builder setFilter(String filter) { + delegate.setFilter(filter); return this; } @Override + @Deprecated public Builder versionFormat(VersionFormat versionFormat) { - delegate.versionFormat(versionFormat); + delegate.setVersionFormat(versionFormat); + return this; + } + + @Override + public Builder setVersionFormat(VersionFormat versionFormat) { + delegate.setVersionFormat(versionFormat); return this; } @@ -124,10 +152,18 @@ public final boolean equals(Object obj) { /** * Returns the sinks's {@code Logging} object used to issue requests. */ + @Deprecated public Logging logging() { return logging; } + /** + * Returns the sinks's {@code Logging} object used to issue requests. + */ + public Logging getLogging() { + return logging; + } + /** * Deletes this sink. * @@ -145,7 +181,7 @@ public Logging logging() { * @throws LoggingException upon failure */ public boolean delete() { - return logging.deleteSink(name()); + return logging.deleteSink(getName()); } /** @@ -168,7 +204,7 @@ public boolean delete() { * @throws LoggingException upon failure */ public Future deleteAsync() { - return logging.deleteSinkAsync(name()); + return logging.deleteSinkAsync(getName()); } /** @@ -186,7 +222,7 @@ public Future deleteAsync() { * @throws LoggingException upon failure */ public Sink reload() { - return logging.getSink(name()); + return logging.getSink(getName()); } /** @@ -207,7 +243,7 @@ public Sink reload() { * @throws LoggingException upon failure */ public Future reloadAsync() { - return logging.getSinkAsync(name()); + return logging.getSinkAsync(getName()); } /** 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..63b603dcec04 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,10 +95,18 @@ public static final class BucketDestination extends Destination { /** * Returns the name of the Google Cloud Storage bucket this destination represents. */ + @Deprecated public String bucket() { return bucket; } + /** + * Returns the name of the Google Cloud Storage bucket this destination represents. + */ + public String getBucket() { + return bucket; + } + @Override public boolean equals(Object obj) { if (obj == this) { @@ -171,17 +179,34 @@ 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 project; } + /** + * 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 dataset; } + /** + * Returns the name of the Google Cloud BigQuery dataset this destination represents. + */ + public String getDataset() { + return dataset; + } + @Override public boolean equals(Object obj) { if (obj == this) { @@ -267,17 +292,34 @@ 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 project; } + /** + * 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 topic; } + /** + * Returns the name of the Google Cloud Pub/Sub topic this destination represents. + */ + public String getTopic() { + return topic; + } + @Override public boolean equals(Object obj) { if (obj == this) { @@ -347,10 +389,18 @@ static TopicDestination fromPb(String destinationPb) { /** * Returns the type of this destination. */ + @Deprecated public Type type() { return type; } + /** + * Returns the type of this destination. + */ + public Type getType() { + return type; + } + final boolean baseEquals(Destination other) { return type.equals(other.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,29 +567,57 @@ static final class BuilderImpl extends Builder { } @Override + @Deprecated public Builder name(String name) { this.name = name; return this; } @Override + public Builder setName(String name) { + this.name = name; + return this; + } + + @Override + @Deprecated public Builder destination(Destination destination) { this.destination = destination; return this; } @Override + public Builder setDestination(Destination destination) { + this.destination = destination; + return this; + } + + @Override + @Deprecated public Builder filter(String filter) { this.filter = filter; return this; } @Override + public Builder setFilter(String filter) { + this.filter = filter; + return this; + } + + @Override + @Deprecated public Builder versionFormat(VersionFormat versionFormat) { this.versionFormat = versionFormat; return this; } + @Override + public Builder setVersionFormat(VersionFormat versionFormat) { + this.versionFormat = versionFormat; + return this; + } + @Override public SinkInfo build() { return new SinkInfo(this); @@ -516,10 +636,20 @@ 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 name; } + /** + * 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; + } + /** * Returns the export destination. This method returns a {@link Destination.BucketDestination} for * sinks that export logs to Google Cloud Storage buckets. Returns @@ -531,10 +661,26 @@ public String name() { * Exporting Logs */ @SuppressWarnings("unchecked") + @Deprecated public T destination() { return (T) destination; } + /** + * 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; + } + /** * 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 @@ -544,19 +690,43 @@ public T destination() { * @see Advanced Log * Filters */ + @Deprecated public String filter() { return filter; } + /** + * 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; + } + /** * 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. */ + @Deprecated public VersionFormat versionFormat() { return versionFormat; } + /** + * 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; + } + @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -600,10 +770,18 @@ 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 new BuilderImpl(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); + } + /** * Creates a {@code SinkInfo} object given the name of the sink and its destination. */ @@ -624,11 +802,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/testing/RemoteLoggingHelper.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/RemoteLoggingHelper.java index 48b7c183d5a8..2d19e7cc03fa 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,10 +47,18 @@ private RemoteLoggingHelper(LoggingOptions options) { /** * Returns a {@link LoggingOptions} object to be used for testing. */ + @Deprecated public LoggingOptions options() { return options; } + /** + * Returns a {@link LoggingOptions} object to be used for testing. + */ + public LoggingOptions getOptions() { + return options; + } + /** * Creates a {@code RemoteLoggingHelper} object for the given project id and JSON key input * stream. 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 f5693dedbc36..6b9c7aa94ae2 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 @@ -91,25 +91,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()); } @@ -118,25 +118,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()); } @@ -144,36 +144,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()); } @@ -217,7 +217,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)); @@ -231,7 +231,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)); @@ -241,22 +241,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()); } @@ -265,22 +265,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()); } @@ -288,28 +288,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()); } @@ -352,19 +352,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)); @@ -377,32 +377,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)); } @@ -412,13 +412,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(); @@ -429,26 +429,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()); } @@ -483,18 +483,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); @@ -523,17 +524,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