Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1565 from zalando/revert-merge-to-main
Browse files Browse the repository at this point in the history
Revert master branch to the latest deployed commit
  • Loading branch information
1u0 authored Oct 30, 2023
2 parents 1f15548 + 845215a commit 17d932e
Show file tree
Hide file tree
Showing 60 changed files with 314 additions and 894 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.zalando.nakadi.utils.TestUtils.buildDefaultEventType;
import static org.zalando.nakadi.utils.TestUtils.randomTextString;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

import static java.util.Collections.emptySet;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.zalando.nakadi.utils.TestUtils.createRandomSubscriptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import static com.jayway.restassured.RestAssured.given;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.zalando.nakadi.domain.SubscriptionBase.InitialPosition.END;
import static org.zalando.nakadi.utils.TestUtils.waitFor;
import static org.zalando.nakadi.webservice.utils.NakadiTestUtils.createEventType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.apache.avro.io.DecoderFactory;
import org.apache.avro.io.EncoderFactory;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.core.io.DefaultResourceLoader;
Expand All @@ -34,6 +33,7 @@
import java.nio.ByteBuffer;
import java.time.Instant;
import java.util.List;
import java.util.Map;

import static com.jayway.restassured.RestAssured.given;
import static org.zalando.nakadi.domain.SubscriptionBase.InitialPosition.BEGIN;
Expand Down Expand Up @@ -119,10 +119,10 @@ public void shouldPublishAvroAndConsumeJsonAndAvro() throws IOException {
final TestStreamingClient client1 = TestStreamingClient.create(subscription1.getId()).start();

TestUtils.waitFor(() -> Assert.assertEquals(1, client1.getJsonBatches().size()));
final JSONObject jsonEvent = client1.getJsonBatches().get(0).getEvents().get(0);
final Map jsonEvent = client1.getJsonBatches().get(0).getEvents().get(0);
Assert.assertEquals("bar", jsonEvent.get("foo"));

final JSONObject metadata = jsonEvent.getJSONObject("metadata");
final Map<String, Object> metadata = (Map<String, Object>) jsonEvent.get("metadata");
Assert.assertEquals("CE8C9EBC-3F19-4B9D-A453-08AD2EDA6028", metadata.get("eid"));
Assert.assertEquals("2.0.0", metadata.get("version"));
Assert.assertEquals(testETName, metadata.get("event_type"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.apache.http.HttpStatus;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import org.zalando.nakadi.domain.Subscription;
Expand All @@ -13,6 +12,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Map;

import static com.jayway.restassured.RestAssured.given;

Expand Down Expand Up @@ -43,7 +43,7 @@ public void testNakadiAccessLogInAvro() throws Exception {
// So the test is only looking for a valid event.
Assert.assertEquals(
NAKADI_ACCESS_LOG,
event.getJSONObject("metadata").get("event_type"));
((Map) event.get("metadata")).get("event_type"));
Assert.assertNotNull(event.get("method"));
Assert.assertNotNull(event.get("path"));
Assert.assertNotNull(event.get("query"));
Expand All @@ -56,7 +56,7 @@ public void testNakadiAccessLogInAvro() throws Exception {
Assert.assertNotNull(event.get("content_encoding"));
Assert.assertNotNull(event.get("request_length"));
Assert.assertNotNull(event.get("response_length"));
Assert.assertFalse(event.has("random_key"));
Assert.assertNull(event.get("random_key"));
}

@Test
Expand All @@ -75,7 +75,7 @@ public void testNakadiSubscriptionLogInAvro() throws Exception {
// So the test is only looking for a valid event.
Assert.assertEquals(
NAKADI_SUBSCRIPTION_LOG,
event.getJSONObject("metadata").get("event_type"));
((Map) event.get("metadata")).get("event_type"));
Assert.assertEquals("created", event.get("status"));
Assert.assertNotNull(event.get("subscription_id"));
}
Expand All @@ -96,7 +96,7 @@ public void testNakadiEventTypeLogInAvro() throws Exception {
// So the test is only looking for a valid event.
Assert.assertEquals(
NAKADI_EVENT_TYPE_LOG,
event.getJSONObject("metadata").get("event_type"));
((Map) event.get("metadata")).get("event_type"));
Assert.assertNotNull(event.get("event_type"));
Assert.assertNotNull(event.get("status"));
Assert.assertNotNull(event.get("category"));
Expand All @@ -120,7 +120,7 @@ public void testNakadiBatchPublishedInAvro() throws Exception {
// So the test is only looking for a valid event.
Assert.assertEquals(
NAKADI_BATCH_PUBLISHED,
event.getJSONObject("metadata").get("event_type"));
((Map) event.get("metadata")).get("event_type"));
Assert.assertNotNull(event.get("event_type"));
Assert.assertNotNull(event.get("app"));
Assert.assertNotNull(event.get("app_hashed"));
Expand All @@ -145,7 +145,7 @@ public void testNakadiDataStreamedInAvro() throws Exception {
final var event = events.get(0);
// All acceptance tests are run against same instance, so the exact event that is consumed is unpredictable.
// So the test is only looking for a valid event.
final var metadata = event.getJSONObject("metadata");
final var metadata = (Map) event.get("metadata");
Assert.assertEquals(NAKADI_DATA_STREAMED, metadata.get("event_type"));
Assert.assertNotNull(metadata.get("occurred_at"));
Assert.assertNotNull(metadata.get("received_at"));
Expand All @@ -162,7 +162,7 @@ public void testNakadiDataStreamedInAvro() throws Exception {
Assert.assertNotNull(event.get("batches_streamed"));
}

private List<JSONObject> consumeEvent(final TestStreamingClient client) {
private List<Map> consumeEvent(final TestStreamingClient client) {
TestUtils.waitFor(() -> MatcherAssert.assertThat(
client.getJsonBatches().size(), Matchers.greaterThanOrEqualTo(1)), 10000);
return client.getJsonBatches().get(0).getEvents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.zalando.nakadi.utils.EventTypeTestBuilder;
import org.zalando.nakadi.webservice.utils.NakadiTestUtils;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
import static org.zalando.nakadi.utils.TestUtils.randomTextString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
import static com.jayway.restassured.http.ContentType.JSON;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.zalando.nakadi.utils.TestUtils.buildDefaultEventType;
import static org.zalando.nakadi.utils.TestUtils.randomTextString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.MINUTES;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.zalando.nakadi.util.DateWithinMatcher.dateWithin;

public class TimelinesControllerAT extends BaseAT {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Header;
import com.jayway.restassured.specification.RequestSpecification;
import org.echocat.jomon.runtime.concurrent.RetryForSpecifiedTimeStrategy;
import org.json.JSONArray;
import org.hamcrest.Matchers;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -29,16 +30,13 @@

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static java.util.stream.LongStream.rangeClosed;
import static org.echocat.jomon.runtime.concurrent.Retryer.executeWithRetry;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT;
Expand All @@ -50,6 +48,7 @@
import static org.zalando.nakadi.utils.TestUtils.randomUUID;
import static org.zalando.nakadi.utils.TestUtils.randomValidEventTypeName;
import static org.zalando.nakadi.utils.TestUtils.waitFor;
import static org.zalando.nakadi.webservice.hila.StreamBatch.MatcherIgnoringToken.equalToBatchIgnoringToken;
import static org.zalando.nakadi.webservice.utils.NakadiTestUtils.commitCursors;
import static org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription;

Expand Down Expand Up @@ -116,12 +115,12 @@ public void userJourneyM1() throws InterruptedException, IOException {
.get("/event-types")
.then()
.statusCode(OK.value())
.body("size()", greaterThan(0))
.body("name[0]", notNullValue())
.body("owning_application[0]", notNullValue())
.body("category[0]", notNullValue())
.body("schema.type[0]", notNullValue())
.body("schema.schema[0]", notNullValue());
.body("size()", Matchers.greaterThan(0))
.body("name[0]", Matchers.notNullValue())
.body("owning_application[0]", Matchers.notNullValue())
.body("category[0]", Matchers.notNullValue())
.body("schema.type[0]", Matchers.notNullValue())
.body("schema.schema[0]", Matchers.notNullValue());

final String updateEventTypeBody = getUpdateEventType();

Expand Down Expand Up @@ -191,9 +190,9 @@ public void userJourneyM1() throws InterruptedException, IOException {
.get("/event-types/" + eventTypeName + "/partitions")
.then()
.statusCode(OK.value())
.body("size()", equalTo(1)).body("partition[0]", notNullValue())
.body("oldest_available_offset[0]", notNullValue())
.body("newest_available_offset[0]", notNullValue());
.body("size()", equalTo(1)).body("partition[0]", Matchers.notNullValue())
.body("oldest_available_offset[0]", Matchers.notNullValue())
.body("newest_available_offset[0]", Matchers.notNullValue());

// read events
requestSpec()
Expand Down Expand Up @@ -341,19 +340,19 @@ public void userJourneyHila() throws InterruptedException, IOException {
// create client and wait till we receive all events
final TestStreamingClient client = new TestStreamingClient(
RestAssured.baseURI + ":" + RestAssured.port, subscription.getId(), "", oauthToken).start();
waitFor(() -> assertThat(client.getJsonBatches(), hasSize(4)));
waitFor(() -> assertThat(client.getJsonBatches(), Matchers.hasSize(4)));
final List<StreamBatch> batches = client.getJsonBatches();

// validate the content of events
for (int i = 0; i < batches.size(); i++) {
final SubscriptionCursor cursor = new SubscriptionCursor("0", TestUtils.toTimelineOffset(i),
eventTypeName, "");
final StreamBatch expectedBatch = new StreamBatch(cursor,
new JSONArray().put(new JSONObject().put("foo", "bar" + i)),
ImmutableList.of(ImmutableMap.of("foo", "bar" + i)),
i == 0 ? new StreamMetadata("Stream started") : null);

final StreamBatch batch = batches.get(i);
assertThat(batch, StreamBatch.equalToBatchIgnoringToken(expectedBatch));
assertThat(batch, equalToBatchIgnoringToken(expectedBatch));
}

// as we didn't commit, there should be still 4 unconsumed events
Expand All @@ -362,7 +361,7 @@ public void userJourneyHila() throws InterruptedException, IOException {
.then()
.statusCode(OK.value())
.body("items[0].partitions[0].unconsumed_events", equalTo(4))
.body("items[0].partitions[0].consumer_lag_seconds", greaterThanOrEqualTo(0));
.body("items[0].partitions[0].consumer_lag_seconds", Matchers.greaterThanOrEqualTo(0));

// commit cursor of latest event
final StreamBatch lastBatch = batches.get(batches.size() - 1);
Expand Down Expand Up @@ -443,14 +442,13 @@ public void userJourneyAvroTransition() throws InterruptedException, IOException
final TestStreamingClient client = new TestStreamingClient(
RestAssured.baseURI + ":" + RestAssured.port, subscription.getId(), "", oauthToken).start();

waitFor(() -> assertThat(client.getJsonBatches(), hasSize(4)));
waitFor(() -> assertThat(client.getJsonBatches(), Matchers.hasSize(4)));
final List<StreamBatch> batches = client.getJsonBatches();

// validate the events metadata
for (final StreamBatch batch : batches) {
assertThat(
batch.getEvents().get(0).getJSONObject("metadata").getString("version"),
equalTo(validatedWithJsonSchemaVersion));
final Map<String, String> metadata = (Map<String, String>) batch.getEvents().get(0).get("metadata");
assertThat(metadata.get("version"), equalTo(validatedWithJsonSchemaVersion));
}

// delete subscription
Expand Down
Loading

0 comments on commit 17d932e

Please sign in to comment.