From 511f13e687018033e4cfea3e7afb6b0028be773b Mon Sep 17 00:00:00 2001 From: Kunal Jha Date: Fri, 2 Nov 2018 14:49:49 +0100 Subject: [PATCH 1/8] Added updated at to subscription --- .../org/zalando/nakadi/domain/Subscription.java | 17 ++++++++++++----- .../subscription/SubscriptionService.java | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/zalando/nakadi/domain/Subscription.java b/src/main/java/org/zalando/nakadi/domain/Subscription.java index 2e1ef62b26..854d6f10b9 100644 --- a/src/main/java/org/zalando/nakadi/domain/Subscription.java +++ b/src/main/java/org/zalando/nakadi/domain/Subscription.java @@ -9,6 +9,12 @@ public class Subscription extends SubscriptionBase { + private String id; + private DateTime createdAt; + private DateTime updatedAt; + @JsonInclude(JsonInclude.Include.NON_NULL) + private List status; + public Subscription() { super(); } @@ -19,12 +25,13 @@ public Subscription(final String id, final DateTime createdAt, final Subscriptio this.createdAt = createdAt; } - private String id; - - private DateTime createdAt; + public DateTime getUpdatedAt() { + return updatedAt; + } - @JsonInclude(JsonInclude.Include.NON_NULL) - private List status; + public void setUpdatedAt(final DateTime updatedAt) { + this.updatedAt = updatedAt; + } public String getId() { return id; diff --git a/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java b/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java index 4b56a9abe9..a30ab12069 100644 --- a/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java +++ b/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import org.joda.time.DateTime; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -144,6 +145,7 @@ public Subscription updateSubscription(final String subscriptionId, final Subscr subscriptionValidationService.validateSubscriptionChange(old, newValue); old.mergeFrom(newValue); + old.setUpdatedAt(new DateTime()); subscriptionRepository.updateSubscription(old); return old; } From 652ebfecc7956bcf4ca53bddec6f912c8420af60 Mon Sep 17 00:00:00 2001 From: Kunal Jha Date: Thu, 8 Nov 2018 14:42:46 +0100 Subject: [PATCH 2/8] added the test,documentation and default value for updated_At --- docs/_data/nakadi-event-bus-api.yaml | 11 +++++++- .../webservice/hila/SubscriptionAT.java | 28 ++++++++++++++++++- .../zalando/nakadi/domain/Subscription.java | 16 +++++++---- .../subscription/SubscriptionService.java | 1 + .../utils/RandomSubscriptionBuilder.java | 1 + 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/docs/_data/nakadi-event-bus-api.yaml b/docs/_data/nakadi-event-bus-api.yaml index 1003787656..bdec2cf450 100644 --- a/docs/_data/nakadi-event-bus-api.yaml +++ b/docs/_data/nakadi-event-bus-api.yaml @@ -1042,7 +1042,8 @@ paths: - oauth2: ['nakadi.event_stream.read'] description: | This endpoint only allows to update the authorization section of a subscription. All other properties are - immutable. This operation is restricted to subjects with administrative role. + immutable. This operation is restricted to subjects with administrative role. This call captures the timestamp + of the update request. parameters: - name: subscription in: body @@ -2423,6 +2424,14 @@ definitions: specified when creating subscription and sending it may result in a client error. format: RFC 3339 date-time example: '1996-12-19T16:39:57-08:00' + updated_at: + type: string + readOnly: true + description: | + Timestamp of last updation of the subscription. This is generated by Nakadi. It should not be + specified when creating subscription and sending it may result in a client error. + format: RFC 3339 date-time + example: '1996-12-19T16:39:57-08:00' read_from: type: string description: | diff --git a/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java b/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java index a4fcbfa1fa..6ce96cc767 100644 --- a/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java +++ b/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java @@ -19,7 +19,9 @@ import org.zalando.nakadi.domain.ItemsWrapper; import org.zalando.nakadi.domain.PaginationLinks; import org.zalando.nakadi.domain.PaginationWrapper; +import org.zalando.nakadi.domain.ResourceAuthorizationAttribute; import org.zalando.nakadi.domain.Subscription; +import org.zalando.nakadi.domain.SubscriptionAuthorization; import org.zalando.nakadi.domain.SubscriptionBase; import org.zalando.nakadi.domain.SubscriptionEventTypeStats; import org.zalando.nakadi.utils.JsonTestHelper; @@ -35,6 +37,7 @@ import org.zalando.problem.Problem; import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -110,11 +113,13 @@ public void testSubscriptionBaseOperations() throws IOException { .body("consumer_group", not(isEmptyString())) .body("id", not(isEmptyString())) .body("created_at", not(isEmptyString())) + .body("updated_at", not(isEmptyString())) .body("start_from", not(isEmptyString())); // retrieve subscription object from response final Subscription subFirst = MAPPER.readValue(response.print(), Subscription.class); - + //check initialization of updated_At + assertThat(subFirst.getUpdatedAt(), equalTo(subFirst.getCreatedAt())); // when we try to create that subscription again - we should get status 200 // and the subscription that already exists should be returned response = given() @@ -137,6 +142,27 @@ public void testSubscriptionBaseOperations() throws IOException { response.then().statusCode(HttpStatus.SC_OK).contentType(JSON); final Subscription gotSubscription = MAPPER.readValue(response.print(), Subscription.class); assertThat(gotSubscription, equalTo(subFirst)); + + //Check for updation of the subscription + final Subscription updateSub= subFirst; + updateSub.setAuthorization(new SubscriptionAuthorization( + Collections.singletonList(new ResourceAuthorizationAttribute("user", "me")), + Collections.singletonList(new ResourceAuthorizationAttribute("user", "me")))); + final String updatedSubscription = MAPPER.writeValueAsString(updateSub); + + response = given() + .body(updatedSubscription) + .contentType(JSON) + .put(format(SUBSCRIPTION_URL, subFirst.getId())); + + response + .then() + .statusCode(HttpStatus.SC_NO_CONTENT); + + response = get(format(SUBSCRIPTION_URL, subFirst.getId())); + response.then().statusCode(HttpStatus.SC_OK).contentType(JSON); + final Subscription updatedSub = MAPPER.readValue(response.print(), Subscription.class); + assertThat(updatedSub.getUpdatedAt(), not(equalTo(subFirst.getUpdatedAt()))); } @Test diff --git a/src/main/java/org/zalando/nakadi/domain/Subscription.java b/src/main/java/org/zalando/nakadi/domain/Subscription.java index 854d6f10b9..ca58220017 100644 --- a/src/main/java/org/zalando/nakadi/domain/Subscription.java +++ b/src/main/java/org/zalando/nakadi/domain/Subscription.java @@ -9,12 +9,6 @@ public class Subscription extends SubscriptionBase { - private String id; - private DateTime createdAt; - private DateTime updatedAt; - @JsonInclude(JsonInclude.Include.NON_NULL) - private List status; - public Subscription() { super(); } @@ -23,8 +17,18 @@ public Subscription(final String id, final DateTime createdAt, final Subscriptio super(subscriptionBase); this.id = id; this.createdAt = createdAt; + this.updatedAt=createdAt; } + private String id; + + private DateTime createdAt; + + private DateTime updatedAt; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private List status; + public DateTime getUpdatedAt() { return updatedAt; } diff --git a/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java b/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java index a30ab12069..7d5e259d0a 100644 --- a/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java +++ b/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java @@ -55,6 +55,7 @@ import org.zalando.nakadi.util.SubscriptionsUriHelper; import org.zalando.nakadi.view.SubscriptionCursorWithoutToken; + import javax.annotation.Nullable; import java.time.Duration; import java.util.ArrayList; diff --git a/src/test/java/org/zalando/nakadi/utils/RandomSubscriptionBuilder.java b/src/test/java/org/zalando/nakadi/utils/RandomSubscriptionBuilder.java index 19f3fd562c..0143e26adf 100644 --- a/src/test/java/org/zalando/nakadi/utils/RandomSubscriptionBuilder.java +++ b/src/test/java/org/zalando/nakadi/utils/RandomSubscriptionBuilder.java @@ -83,6 +83,7 @@ public Subscription build() { final Subscription subscription = new Subscription(); subscription.setId(id); subscription.setCreatedAt(createdAt); + subscription.setUpdatedAt(createdAt); subscription.setOwningApplication(owningApplication); subscription.setEventTypes(eventTypes); subscription.setConsumerGroup(consumerGroup); From f77b957b9e2d483c744b769ac177e8b6d2241eec Mon Sep 17 00:00:00 2001 From: Kunal Jha Date: Fri, 9 Nov 2018 13:40:03 +0100 Subject: [PATCH 3/8] removed updated_at from the randomsubscriptionbuilder --- docs/_data/nakadi-event-bus-api.yaml | 3 ++- .../nakadi/controller/SubscriptionControllerTest.java | 5 +++++ .../org/zalando/nakadi/service/SubscriptionServiceTest.java | 1 + .../org/zalando/nakadi/utils/RandomSubscriptionBuilder.java | 1 - 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/_data/nakadi-event-bus-api.yaml b/docs/_data/nakadi-event-bus-api.yaml index bdec2cf450..b7816d8015 100644 --- a/docs/_data/nakadi-event-bus-api.yaml +++ b/docs/_data/nakadi-event-bus-api.yaml @@ -2429,7 +2429,8 @@ definitions: readOnly: true description: | Timestamp of last updation of the subscription. This is generated by Nakadi. It should not be - specified when creating subscription and sending it may result in a client error. + specified when creating subscription and sending it may result in a client error. Its initial value is same + as created_at. format: RFC 3339 date-time example: '1996-12-19T16:39:57-08:00' read_from: diff --git a/src/test/java/org/zalando/nakadi/controller/SubscriptionControllerTest.java b/src/test/java/org/zalando/nakadi/controller/SubscriptionControllerTest.java index c0d7b8231a..17b8d8a3ab 100644 --- a/src/test/java/org/zalando/nakadi/controller/SubscriptionControllerTest.java +++ b/src/test/java/org/zalando/nakadi/controller/SubscriptionControllerTest.java @@ -140,6 +140,7 @@ public SubscriptionControllerTest() throws Exception { @Test public void whenGetSubscriptionThenOk() throws Exception { final Subscription subscription = builder().build(); + subscription.setUpdatedAt(subscription.getCreatedAt()); when(subscriptionRepository.getSubscription(subscription.getId())).thenReturn(subscription); getSubscription(subscription.getId()) @@ -150,6 +151,7 @@ public void whenGetSubscriptionThenOk() throws Exception { @Test public void whenGetNoneExistingSubscriptionThenNotFound() throws Exception { final Subscription subscription = builder().build(); + subscription.setUpdatedAt(subscription.getCreatedAt()); when(subscriptionRepository.getSubscription(subscription.getId())) .thenThrow(new NoSuchSubscriptionException("dummy-message")); final ThrowableProblem expectedProblem = Problem.valueOf(NOT_FOUND, "dummy-message"); @@ -237,6 +239,7 @@ public void whenGetSubscriptionAndExceptionThenServiceUnavailable() throws Excep @Test public void whenGetSubscriptionStatThenOk() throws Exception { final Subscription subscription = builder().withEventType(TIMELINE.getEventType()).build(); + subscription.setUpdatedAt(subscription.getCreatedAt()); final Collection partitions = Collections.singleton( new Partition(TIMELINE.getEventType(), "0", "xz", null, Partition.State.ASSIGNED)); final ZkSubscriptionNode zkSubscriptionNode = @@ -278,6 +281,7 @@ public void whenGetSubscriptionStatThenOk() throws Exception { @SuppressWarnings("unchecked") public void whenGetSubscriptionNoEventTypesThenStatEmpty() throws Exception { final Subscription subscription = builder().withEventType("myET").build(); + subscription.setUpdatedAt(subscription.getCreatedAt()); when(subscriptionRepository.getSubscription(subscription.getId())).thenReturn(subscription); when(zkSubscriptionClient.getZkSubscriptionNode()).thenReturn( Optional.of(new ZkSubscriptionNode(Collections.emptyList(), Collections.emptyList()))); @@ -326,6 +330,7 @@ private void mockGetFromRepoSubscriptionWithOwningApp(final String subscriptionI .withId(subscriptionId) .withOwningApplication(owningApplication) .build(); + subscription.setUpdatedAt(subscription.getCreatedAt()); when(subscriptionRepository.getSubscription(subscriptionId)).thenReturn(subscription); } diff --git a/src/test/java/org/zalando/nakadi/service/SubscriptionServiceTest.java b/src/test/java/org/zalando/nakadi/service/SubscriptionServiceTest.java index 70bebfa13e..f9bfdef905 100644 --- a/src/test/java/org/zalando/nakadi/service/SubscriptionServiceTest.java +++ b/src/test/java/org/zalando/nakadi/service/SubscriptionServiceTest.java @@ -65,6 +65,7 @@ public void whenSubscriptionCreatedThenKPIEventSubmitted() { final Subscription subscription = RandomSubscriptionBuilder.builder() .withId("my_subscription_id1") .build(); + subscription.setUpdatedAt(subscription.getCreatedAt()); when(subscriptionRepository.createSubscription(subscriptionBase)).thenReturn(subscription); subscriptionService.createSubscription(subscriptionBase); diff --git a/src/test/java/org/zalando/nakadi/utils/RandomSubscriptionBuilder.java b/src/test/java/org/zalando/nakadi/utils/RandomSubscriptionBuilder.java index 0143e26adf..19f3fd562c 100644 --- a/src/test/java/org/zalando/nakadi/utils/RandomSubscriptionBuilder.java +++ b/src/test/java/org/zalando/nakadi/utils/RandomSubscriptionBuilder.java @@ -83,7 +83,6 @@ public Subscription build() { final Subscription subscription = new Subscription(); subscription.setId(id); subscription.setCreatedAt(createdAt); - subscription.setUpdatedAt(createdAt); subscription.setOwningApplication(owningApplication); subscription.setEventTypes(eventTypes); subscription.setConsumerGroup(consumerGroup); From 1b3069a8805d4aa9a4a2e7dcd647ff802b40efca Mon Sep 17 00:00:00 2001 From: Kunal Jha Date: Wed, 14 Nov 2018 13:34:31 +0100 Subject: [PATCH 4/8] added timezone --- .../nakadi/service/subscription/SubscriptionService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java b/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java index 7d5e259d0a..ced6727fc4 100644 --- a/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java +++ b/src/main/java/org/zalando/nakadi/service/subscription/SubscriptionService.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -146,7 +147,7 @@ public Subscription updateSubscription(final String subscriptionId, final Subscr subscriptionValidationService.validateSubscriptionChange(old, newValue); old.mergeFrom(newValue); - old.setUpdatedAt(new DateTime()); + old.setUpdatedAt(new DateTime(DateTimeZone.UTC)); subscriptionRepository.updateSubscription(old); return old; } From 91d6f5ba790be6d7fcb79e7d53b9a1ff2b0d8c5b Mon Sep 17 00:00:00 2001 From: Kunal Jha Date: Mon, 19 Nov 2018 15:07:14 +0100 Subject: [PATCH 5/8] fixed the reviews --- docs/_data/nakadi-event-bus-api.yaml | 2 +- .../nakadi/webservice/hila/SubscriptionAT.java | 3 +-- .../java/org/zalando/nakadi/domain/Subscription.java | 5 +++-- .../repository/db/SubscriptionDbRepository.java | 2 +- .../controller/PostSubscriptionControllerTest.java | 11 ++++++----- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/_data/nakadi-event-bus-api.yaml b/docs/_data/nakadi-event-bus-api.yaml index b7816d8015..349d59e887 100644 --- a/docs/_data/nakadi-event-bus-api.yaml +++ b/docs/_data/nakadi-event-bus-api.yaml @@ -2428,7 +2428,7 @@ definitions: type: string readOnly: true description: | - Timestamp of last updation of the subscription. This is generated by Nakadi. It should not be + Timestamp of last update of the subscription. This is generated by Nakadi. It should not be specified when creating subscription and sending it may result in a client error. Its initial value is same as created_at. format: RFC 3339 date-time diff --git a/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java b/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java index 6ce96cc767..39f9e12020 100644 --- a/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java +++ b/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java @@ -113,7 +113,6 @@ public void testSubscriptionBaseOperations() throws IOException { .body("consumer_group", not(isEmptyString())) .body("id", not(isEmptyString())) .body("created_at", not(isEmptyString())) - .body("updated_at", not(isEmptyString())) .body("start_from", not(isEmptyString())); // retrieve subscription object from response @@ -143,7 +142,7 @@ public void testSubscriptionBaseOperations() throws IOException { final Subscription gotSubscription = MAPPER.readValue(response.print(), Subscription.class); assertThat(gotSubscription, equalTo(subFirst)); - //Check for updation of the subscription + //Check for update time of the subscription final Subscription updateSub= subFirst; updateSub.setAuthorization(new SubscriptionAuthorization( Collections.singletonList(new ResourceAuthorizationAttribute("user", "me")), diff --git a/src/main/java/org/zalando/nakadi/domain/Subscription.java b/src/main/java/org/zalando/nakadi/domain/Subscription.java index ca58220017..dfd1021b9a 100644 --- a/src/main/java/org/zalando/nakadi/domain/Subscription.java +++ b/src/main/java/org/zalando/nakadi/domain/Subscription.java @@ -13,11 +13,12 @@ public Subscription() { super(); } - public Subscription(final String id, final DateTime createdAt, final SubscriptionBase subscriptionBase) { + public Subscription(final String id, final DateTime createdAt, final DateTime updatedAt, + final SubscriptionBase subscriptionBase) { super(subscriptionBase); this.id = id; this.createdAt = createdAt; - this.updatedAt=createdAt; + this.updatedAt = updatedAt; } private String id; diff --git a/src/main/java/org/zalando/nakadi/repository/db/SubscriptionDbRepository.java b/src/main/java/org/zalando/nakadi/repository/db/SubscriptionDbRepository.java index ec8e7d5fdc..384c1c3d82 100644 --- a/src/main/java/org/zalando/nakadi/repository/db/SubscriptionDbRepository.java +++ b/src/main/java/org/zalando/nakadi/repository/db/SubscriptionDbRepository.java @@ -62,7 +62,7 @@ public Subscription createSubscription(final SubscriptionBase subscriptionBase) final String newId = uuidGenerator.randomUUID().toString(); final String keyFieldsHash = hashGenerator.generateSubscriptionKeyFieldsHash(subscriptionBase); final DateTime createdAt = new DateTime(DateTimeZone.UTC); - final Subscription subscription = new Subscription(newId, createdAt, subscriptionBase); + final Subscription subscription = new Subscription(newId, createdAt, createdAt,subscriptionBase); jdbcTemplate.update("INSERT INTO zn_data.subscription (s_id, s_subscription_object, s_key_fields_hash) " + "VALUES (?, ?::JSONB, ?)", diff --git a/src/test/java/org/zalando/nakadi/controller/PostSubscriptionControllerTest.java b/src/test/java/org/zalando/nakadi/controller/PostSubscriptionControllerTest.java index 2f38e9072a..4031041735 100644 --- a/src/test/java/org/zalando/nakadi/controller/PostSubscriptionControllerTest.java +++ b/src/test/java/org/zalando/nakadi/controller/PostSubscriptionControllerTest.java @@ -86,8 +86,8 @@ public void whenSubscriptionCreationIsDisabledThenCreationFails() throws Excepti @Test public void whenSubscriptionCreationDisabledThenReturnExistentSubscription() throws Exception { final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase(); - final Subscription existingSubscription = new Subscription("123", new DateTime(DateTimeZone.UTC), - subscriptionBase); + final DateTime createdAt= new DateTime(DateTimeZone.UTC); + final Subscription existingSubscription = new Subscription("123",createdAt,createdAt,subscriptionBase); existingSubscription.setReadFrom(SubscriptionBase.InitialPosition.BEGIN); when(subscriptionService.getExistingSubscription(any())).thenReturn(existingSubscription); @@ -104,7 +104,8 @@ public void whenSubscriptionCreationDisabledThenReturnExistentSubscription() thr @Test public void whenPostValidSubscriptionThenOk() throws Exception { final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase(); - final Subscription subscription = new Subscription("123", new DateTime(DateTimeZone.UTC), subscriptionBase); + final DateTime createdAt= new DateTime(DateTimeZone.UTC); + final Subscription subscription = new Subscription("123",createdAt,createdAt,subscriptionBase); when(subscriptionService.getExistingSubscription(any())).thenThrow(new NoSuchSubscriptionException("", null)); when(subscriptionService.createSubscription(any())).thenReturn(subscription); @@ -191,8 +192,8 @@ public void whenEventTypeDoesNotExistThenUnprocessableEntity() throws Exception @Test public void whenSubscriptionExistsThenReturnIt() throws Exception { final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase(); - final Subscription existingSubscription = new Subscription("123", new DateTime(DateTimeZone.UTC), - subscriptionBase); + final DateTime createdAt = new DateTime(DateTimeZone.UTC); + final Subscription existingSubscription = new Subscription("123",createdAt,createdAt, subscriptionBase); when(subscriptionService.getExistingSubscription(any())).thenReturn(existingSubscription); when(subscriptionService.createSubscription(any())).thenThrow(new NoSuchEventTypeException("msg")); From 3cf3581a59b12ca6e48e67a30892f45f4003e658 Mon Sep 17 00:00:00 2001 From: Kunal Jha Date: Tue, 20 Nov 2018 11:05:15 +0100 Subject: [PATCH 6/8] fixed intellij formatting problem --- .../nakadi/webservice/hila/SubscriptionAT.java | 4 ++-- .../repository/db/SubscriptionDbRepository.java | 2 +- .../controller/PostSubscriptionControllerTest.java | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java b/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java index 39f9e12020..0adb52f391 100644 --- a/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java +++ b/src/acceptance-test/java/org/zalando/nakadi/webservice/hila/SubscriptionAT.java @@ -143,7 +143,7 @@ public void testSubscriptionBaseOperations() throws IOException { assertThat(gotSubscription, equalTo(subFirst)); //Check for update time of the subscription - final Subscription updateSub= subFirst; + final Subscription updateSub = subFirst; updateSub.setAuthorization(new SubscriptionAuthorization( Collections.singletonList(new ResourceAuthorizationAttribute("user", "me")), Collections.singletonList(new ResourceAuthorizationAttribute("user", "me")))); @@ -166,7 +166,7 @@ public void testSubscriptionBaseOperations() throws IOException { @Test public void testSubscriptionWithNullAuthorisation() { - final EventType eventType = createEventType(); + final EventType eventType = createEventType(); final String subscription = "{\"owning_application\":\"app\",\"event_types\":[\"" + eventType.getName() + "\"], \"read_from\": \"end\", \"consumer_group\":\"test\"," + "\"authorization\": {\"admins\": [], \"readers\": []}}"; diff --git a/src/main/java/org/zalando/nakadi/repository/db/SubscriptionDbRepository.java b/src/main/java/org/zalando/nakadi/repository/db/SubscriptionDbRepository.java index 384c1c3d82..bcad22fc9a 100644 --- a/src/main/java/org/zalando/nakadi/repository/db/SubscriptionDbRepository.java +++ b/src/main/java/org/zalando/nakadi/repository/db/SubscriptionDbRepository.java @@ -62,7 +62,7 @@ public Subscription createSubscription(final SubscriptionBase subscriptionBase) final String newId = uuidGenerator.randomUUID().toString(); final String keyFieldsHash = hashGenerator.generateSubscriptionKeyFieldsHash(subscriptionBase); final DateTime createdAt = new DateTime(DateTimeZone.UTC); - final Subscription subscription = new Subscription(newId, createdAt, createdAt,subscriptionBase); + final Subscription subscription = new Subscription(newId, createdAt, createdAt, subscriptionBase); jdbcTemplate.update("INSERT INTO zn_data.subscription (s_id, s_subscription_object, s_key_fields_hash) " + "VALUES (?, ?::JSONB, ?)", diff --git a/src/test/java/org/zalando/nakadi/controller/PostSubscriptionControllerTest.java b/src/test/java/org/zalando/nakadi/controller/PostSubscriptionControllerTest.java index 4031041735..d83ec8baa7 100644 --- a/src/test/java/org/zalando/nakadi/controller/PostSubscriptionControllerTest.java +++ b/src/test/java/org/zalando/nakadi/controller/PostSubscriptionControllerTest.java @@ -86,8 +86,8 @@ public void whenSubscriptionCreationIsDisabledThenCreationFails() throws Excepti @Test public void whenSubscriptionCreationDisabledThenReturnExistentSubscription() throws Exception { final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase(); - final DateTime createdAt= new DateTime(DateTimeZone.UTC); - final Subscription existingSubscription = new Subscription("123",createdAt,createdAt,subscriptionBase); + final DateTime createdAt = new DateTime(DateTimeZone.UTC); + final Subscription existingSubscription = new Subscription("123", createdAt, createdAt, subscriptionBase); existingSubscription.setReadFrom(SubscriptionBase.InitialPosition.BEGIN); when(subscriptionService.getExistingSubscription(any())).thenReturn(existingSubscription); @@ -104,8 +104,8 @@ public void whenSubscriptionCreationDisabledThenReturnExistentSubscription() thr @Test public void whenPostValidSubscriptionThenOk() throws Exception { final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase(); - final DateTime createdAt= new DateTime(DateTimeZone.UTC); - final Subscription subscription = new Subscription("123",createdAt,createdAt,subscriptionBase); + final DateTime createdAt = new DateTime(DateTimeZone.UTC); + final Subscription subscription = new Subscription("123", createdAt, createdAt, subscriptionBase); when(subscriptionService.getExistingSubscription(any())).thenThrow(new NoSuchSubscriptionException("", null)); when(subscriptionService.createSubscription(any())).thenReturn(subscription); @@ -192,8 +192,8 @@ public void whenEventTypeDoesNotExistThenUnprocessableEntity() throws Exception @Test public void whenSubscriptionExistsThenReturnIt() throws Exception { final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase(); - final DateTime createdAt = new DateTime(DateTimeZone.UTC); - final Subscription existingSubscription = new Subscription("123",createdAt,createdAt, subscriptionBase); + final DateTime createdAt = new DateTime(DateTimeZone.UTC); + final Subscription existingSubscription = new Subscription("123", createdAt, createdAt, subscriptionBase); when(subscriptionService.getExistingSubscription(any())).thenReturn(existingSubscription); when(subscriptionService.createSubscription(any())).thenThrow(new NoSuchEventTypeException("msg")); From c0ef51e43b6d91a3bf926cdda37d7a73adb2ac06 Mon Sep 17 00:00:00 2001 From: Kunal Jha Date: Mon, 26 Nov 2018 16:34:32 +0100 Subject: [PATCH 7/8] added the query to update the exisitng subscriptions --- database/migration/aruha-1954-subscription-add-field.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 database/migration/aruha-1954-subscription-add-field.sql diff --git a/database/migration/aruha-1954-subscription-add-field.sql b/database/migration/aruha-1954-subscription-add-field.sql new file mode 100644 index 0000000000..8fb4dfb555 --- /dev/null +++ b/database/migration/aruha-1954-subscription-add-field.sql @@ -0,0 +1,3 @@ +SET ROLE zalando_nakadi_data_owner; + +UPDATE zn_data.subscription SET s_subscription_object = jsonb_set(s_subscription_object,'{updated_at}',concat('"',s_subscription_object->>'created_at','"' )::jsonb, true); \ No newline at end of file From 05128ea956792a62af179d4ad2605bfc32f8d71d Mon Sep 17 00:00:00 2001 From: Kunal Jha Date: Tue, 27 Nov 2018 10:42:13 +0100 Subject: [PATCH 8/8] fixed the indentation --- database/migration/aruha-1954-subscription-add-field.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database/migration/aruha-1954-subscription-add-field.sql b/database/migration/aruha-1954-subscription-add-field.sql index 8fb4dfb555..feeb281bb7 100644 --- a/database/migration/aruha-1954-subscription-add-field.sql +++ b/database/migration/aruha-1954-subscription-add-field.sql @@ -1,3 +1,4 @@ SET ROLE zalando_nakadi_data_owner; -UPDATE zn_data.subscription SET s_subscription_object = jsonb_set(s_subscription_object,'{updated_at}',concat('"',s_subscription_object->>'created_at','"' )::jsonb, true); \ No newline at end of file +UPDATE zn_data.subscription SET s_subscription_object = jsonb_set(s_subscription_object, '{updated_at}', + concat('"', s_subscription_object ->>'created_at', '"')::jsonb, true);