From 929bb69c443f8c1f427ba9564cd3a2a820b3135b Mon Sep 17 00:00:00 2001 From: abhinav Date: Thu, 11 Jul 2019 15:52:33 +0530 Subject: [PATCH 1/3] deprecated method usage removed --- .../com/google/cloud/logging/SinkInfo.java | 15 +++++------ .../google/cloud/logging/LoggingImplTest.java | 5 +++- .../google/cloud/logging/SinkInfoTest.java | 26 ++++++++++--------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java b/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java index b4cc2940d873..81df65f11a3f 100644 --- a/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java +++ b/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java @@ -578,15 +578,14 @@ public static SinkInfo of(String name, Destination destination) { return new BuilderImpl(name, destination).build(); } + /** Creates a {@code SinkInfo} object given the name of the sink and its destination. */ + public static SinkInfo of(SinkInfo sink) { + return new BuilderImpl(sink).build(); + } + LogSink toPb(String projectId) { LogSink.Builder builder = - LogSink.newBuilder() - .setName(name) - .setDestination(destination.toPb(projectId)) - .setOutputVersionFormat( - versionFormat == null - ? LogSink.VersionFormat.VERSION_FORMAT_UNSPECIFIED - : versionFormat.toPb()); + LogSink.newBuilder().setName(name).setDestination(destination.toPb(projectId)); if (filter != null) { builder.setFilter(filter); } @@ -596,7 +595,7 @@ LogSink toPb(String projectId) { static SinkInfo fromPb(LogSink sinkPb) { Builder builder = newBuilder(sinkPb.getName(), Destination.fromPb(sinkPb.getDestination())) - .setVersionFormat(VersionFormat.fromPb(sinkPb.getOutputVersionFormat())); + .setVersionFormat(VersionFormat.fromPb(LogSink.VersionFormat.V2)); if (!sinkPb.getFilter().equals("")) { builder.setFilter(sinkPb.getFilter()); } diff --git a/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java b/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java index 317271b9f439..07517445097c 100644 --- a/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java +++ b/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java @@ -83,8 +83,11 @@ public class LoggingImplTest { private static final String PROJECT = "project"; private static final String PROJECT_PB = "projects/" + PROJECT; private static final String SINK_NAME = "sink"; + private static final SinkInfo.VersionFormat VERSION = SinkInfo.VersionFormat.V2; private static final SinkInfo SINK_INFO = - SinkInfo.of(SINK_NAME, Destination.BucketDestination.of("bucket")); + SinkInfo.newBuilder(SINK_NAME, Destination.BucketDestination.of("bucket")) + .setVersionFormat(VERSION) + .build(); private static final String SINK_NAME_PB = "projects/" + PROJECT + "/sinks/" + SINK_NAME; private static final String METRIC_NAME = "metric"; private static final String METRIC_NAME_PB = "projects/" + PROJECT + "/metrics/" + METRIC_NAME; diff --git a/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java b/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java index 6deb615e6bb9..65116288c420 100644 --- a/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java +++ b/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java @@ -33,7 +33,7 @@ public class SinkInfoTest { private static final String NAME = "name"; private static final String FILTER = "logName=projects/my-projectid/logs/syslog AND severity>=ERROR"; - private static final VersionFormat VERSION = VersionFormat.V1; + private static final VersionFormat VERSION = VersionFormat.V2; private static final BucketDestination BUCKET_DESTINATION = BucketDestination.of("bucket"); private static final DatasetDestination DATASET_DESTINATION = DatasetDestination.of("project", "dataset"); @@ -120,15 +120,15 @@ public void testBuilder() { 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(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(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()); + // assertEquals(VERSION, TOPIC_SINK_INFO.getVersionFormat()); } @Test @@ -142,19 +142,19 @@ public void testToBuilder() { .setDestination(TOPIC_DESTINATION) .setName("newName") .setFilter("logName=projects/my-projectid/logs/syslog") - .setVersionFormat(VersionFormat.V2) + // .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()); + // assertEquals(VersionFormat.V2, updatedSinkInfo.getVersionFormat()); updatedSinkInfo = BUCKET_SINK_INFO .toBuilder() .setDestination(BUCKET_DESTINATION) .setName(NAME) .setFilter(FILTER) - .setVersionFormat(VersionFormat.V1) + // .setVersionFormat(VersionFormat.V1) .build(); assertEquals(BUCKET_SINK_INFO, updatedSinkInfo); } @@ -164,22 +164,24 @@ public void testToAndFromPb() { compareSinkInfo(BUCKET_SINK_INFO, SinkInfo.fromPb(BUCKET_SINK_INFO.toPb("project"))); compareSinkInfo(DATASET_SINK_INFO, SinkInfo.fromPb(DATASET_SINK_INFO.toPb("project"))); compareSinkInfo(TOPIC_SINK_INFO, SinkInfo.fromPb(TOPIC_SINK_INFO.toPb("project"))); - SinkInfo sinkInfo = SinkInfo.of("name", BUCKET_DESTINATION); + SinkInfo sinkInfo = + SinkInfo.newBuilder(NAME, BUCKET_DESTINATION).setVersionFormat(VERSION).build(); compareSinkInfo(sinkInfo, SinkInfo.fromPb(sinkInfo.toPb("project"))); - sinkInfo = SinkInfo.of("name", DATASET_DESTINATION); + sinkInfo = SinkInfo.newBuilder(NAME, DATASET_DESTINATION).setVersionFormat(VERSION).build(); compareSinkInfo(sinkInfo, SinkInfo.fromPb(sinkInfo.toPb("project"))); - sinkInfo = SinkInfo.of("name", TOPIC_DESTINATION); + sinkInfo = SinkInfo.newBuilder(NAME, TOPIC_DESTINATION).setVersionFormat(VERSION).build(); compareSinkInfo(sinkInfo, SinkInfo.fromPb(sinkInfo.toPb("project"))); } @Test public void testToAndFromPb_NoProjectId() { DatasetDestination datasetDestination = DatasetDestination.of("dataset"); - SinkInfo sinkInfo = SinkInfo.of("name", DATASET_DESTINATION); + SinkInfo sinkInfo = + SinkInfo.newBuilder(NAME, DATASET_DESTINATION).setVersionFormat(VERSION).build(); compareSinkInfo( sinkInfo, SinkInfo.fromPb(SinkInfo.of("name", datasetDestination).toPb("project"))); TopicDestination topicDestination = TopicDestination.of("topic"); - sinkInfo = SinkInfo.of("name", TOPIC_DESTINATION); + sinkInfo = SinkInfo.newBuilder(NAME, TOPIC_DESTINATION).setVersionFormat(VERSION).build(); compareSinkInfo( sinkInfo, SinkInfo.fromPb(SinkInfo.of("name", topicDestination).toPb("project"))); } From f0fc0f3bc3c66723dc55547c682ff6f4bd1e5a38 Mon Sep 17 00:00:00 2001 From: abhinav Date: Thu, 11 Jul 2019 16:45:12 +0530 Subject: [PATCH 2/3] comment removed --- .../main/java/com/google/cloud/logging/SinkInfo.java | 5 ----- .../java/com/google/cloud/logging/SinkInfoTest.java | 12 ++++++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java b/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java index 81df65f11a3f..4b7d8695c7b5 100644 --- a/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java +++ b/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java @@ -578,11 +578,6 @@ public static SinkInfo of(String name, Destination destination) { return new BuilderImpl(name, destination).build(); } - /** Creates a {@code SinkInfo} object given the name of the sink and its destination. */ - public static SinkInfo of(SinkInfo sink) { - return new BuilderImpl(sink).build(); - } - LogSink toPb(String projectId) { LogSink.Builder builder = LogSink.newBuilder().setName(name).setDestination(destination.toPb(projectId)); diff --git a/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java b/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java index 65116288c420..b56ce295d950 100644 --- a/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java +++ b/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/SinkInfoTest.java @@ -120,15 +120,15 @@ public void testBuilder() { 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(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(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()); + assertEquals(VERSION, TOPIC_SINK_INFO.getVersionFormat()); } @Test @@ -142,19 +142,19 @@ public void testToBuilder() { .setDestination(TOPIC_DESTINATION) .setName("newName") .setFilter("logName=projects/my-projectid/logs/syslog") - // .setVersionFormat(VersionFormat.V2) + .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()); + assertEquals(VersionFormat.V2, updatedSinkInfo.getVersionFormat()); updatedSinkInfo = BUCKET_SINK_INFO .toBuilder() .setDestination(BUCKET_DESTINATION) .setName(NAME) .setFilter(FILTER) - // .setVersionFormat(VersionFormat.V1) + .setVersionFormat(VersionFormat.V2) .build(); assertEquals(BUCKET_SINK_INFO, updatedSinkInfo); } From cecff6c30115b0824813382b76649f56fb96c3b8 Mon Sep 17 00:00:00 2001 From: abhinav Date: Fri, 12 Jul 2019 12:47:15 +0530 Subject: [PATCH 3/3] static import changes in LoggingImplTest --- .../test/java/com/google/cloud/logging/LoggingImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java b/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java index 07517445097c..0ca53895bfd0 100644 --- a/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java +++ b/google-cloud-clients/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingImplTest.java @@ -16,6 +16,7 @@ package com.google.cloud.logging; +import static com.google.cloud.logging.SinkInfo.VersionFormat; import static org.easymock.EasyMock.replay; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -83,10 +84,9 @@ public class LoggingImplTest { private static final String PROJECT = "project"; private static final String PROJECT_PB = "projects/" + PROJECT; private static final String SINK_NAME = "sink"; - private static final SinkInfo.VersionFormat VERSION = SinkInfo.VersionFormat.V2; private static final SinkInfo SINK_INFO = SinkInfo.newBuilder(SINK_NAME, Destination.BucketDestination.of("bucket")) - .setVersionFormat(VERSION) + .setVersionFormat(VersionFormat.V2) .build(); private static final String SINK_NAME_PB = "projects/" + PROJECT + "/sinks/" + SINK_NAME; private static final String METRIC_NAME = "metric";