This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ARUHA-473-check-size-of-events
- Loading branch information
Showing
18 changed files
with
839 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
SET ROLE zalando_nakadi_data_owner; | ||
|
||
CREATE TABLE zn_data.storage ( | ||
st_id VARCHAR(36) NOT NULL PRIMARY KEY, | ||
st_type VARCHAR(32) NOT NULL, | ||
st_configuration JSONB NOT NULL | ||
); | ||
|
||
|
||
CREATE TABLE zn_data.timeline ( | ||
tl_id UUID NOT NULL PRIMARY KEY, | ||
et_name VARCHAR(255) NOT NULL REFERENCES zn_data.event_type (et_name), | ||
tl_order INT NOT NULL, | ||
st_id VARCHAR(36) NOT NULL REFERENCES zn_data.storage (st_id), | ||
tl_topic VARCHAR(255) NOT NULL, | ||
tl_created_at TIMESTAMP WITH TIME ZONE NOT NULL, | ||
tl_switched_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, | ||
tl_cleanup_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, | ||
tl_latest_position JSONB DEFAULT NULL, | ||
UNIQUE (et_name, tl_order) | ||
); | ||
|
||
CREATE INDEX ON zn_data.timeline (et_name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE zn_data.storage ( | ||
st_id VARCHAR(36) NOT NULL PRIMARY KEY, | ||
st_type VARCHAR(32) NOT NULL, | ||
st_configuration JSONB NOT NULL | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CREATE TABLE zn_data.timeline ( | ||
tl_id UUID NOT NULL PRIMARY KEY, | ||
et_name VARCHAR(255) NOT NULL REFERENCES zn_data.event_type (et_name), | ||
tl_order INT NOT NULL, | ||
st_id VARCHAR(36) NOT NULL REFERENCES zn_data.storage (st_id), | ||
tl_topic VARCHAR(255) NOT NULL, | ||
tl_created_at TIMESTAMP WITH TIME ZONE NOT NULL, | ||
tl_switched_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, | ||
tl_cleanup_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, | ||
tl_latest_position JSONB DEFAULT NULL, | ||
UNIQUE (et_name, tl_order) | ||
); | ||
|
||
CREATE INDEX ON zn_data.timeline (et_name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/acceptance-test/java/org/zalando/nakadi/repository/db/StorageDbRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.zalando.nakadi.repository.db; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.zalando.nakadi.domain.Storage; | ||
|
||
public class StorageDbRepositoryTest extends AbstractDbRepositoryTest { | ||
private StorageDbRepository repository; | ||
|
||
public StorageDbRepositoryTest() { | ||
super("zn_data.storage"); | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
super.setUp(); | ||
repository = new StorageDbRepository(template, mapper); | ||
} | ||
|
||
static Storage createStorage(final String name, final String zkAddress, final String zkPath) { | ||
final Storage.KafkaConfiguration config = new Storage.KafkaConfiguration(); | ||
config.setZkAddress(zkAddress); | ||
config.setZkPath(zkPath); | ||
final Storage storage = new Storage(); | ||
storage.setId(name); | ||
storage.setType(Storage.Type.KAFKA); | ||
storage.setConfiguration(config); | ||
return storage; | ||
} | ||
|
||
@Test | ||
public void testStorageCreated() { | ||
final Storage storage = createStorage("default", "address", "path"); | ||
|
||
repository.createStorage(storage); | ||
|
||
final Optional<Storage> createdCopy = repository.getStorage(storage.getId()); | ||
Assert.assertTrue(createdCopy.isPresent()); | ||
Assert.assertFalse(createdCopy.get() == storage); | ||
|
||
Assert.assertEquals(storage, createdCopy.get()); | ||
} | ||
|
||
@Test | ||
public void testStorageOrdered() { | ||
final Storage storage2 = repository.createStorage(createStorage("2", "address1", "path3")); | ||
final Storage storage1 = repository.createStorage(createStorage("1", "address2", "path2")); | ||
final Storage storage3 = repository.createStorage(createStorage("3", "address3", "path1")); | ||
|
||
final List<Storage> storages = repository.listStorages(); | ||
Assert.assertEquals(3, storages.size()); | ||
Assert.assertEquals(storage1, storages.get(0)); | ||
Assert.assertEquals(storage2, storages.get(1)); | ||
Assert.assertEquals(storage3, storages.get(2)); | ||
} | ||
|
||
@Test | ||
public void testStorageDeleted() { | ||
final Storage storage = repository.createStorage(createStorage("1", "address2", "path2")); | ||
Assert.assertEquals(storage, repository.getStorage(storage.getId()).get()); | ||
repository.deleteStorage(storage.getId()); | ||
Assert.assertFalse(repository.getStorage(storage.getId()).isPresent()); | ||
Assert.assertEquals(0, repository.listStorages().size()); | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
src/acceptance-test/java/org/zalando/nakadi/repository/db/TimelineDbRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package org.zalando.nakadi.repository.db; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.LongStream; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.dao.DuplicateKeyException; | ||
import org.zalando.nakadi.domain.EventType; | ||
import org.zalando.nakadi.domain.Storage; | ||
import org.zalando.nakadi.domain.Timeline; | ||
import org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException; | ||
import org.zalando.nakadi.exceptions.InternalNakadiException; | ||
import org.zalando.nakadi.utils.TestUtils; | ||
|
||
public class TimelineDbRepositoryTest extends AbstractDbRepositoryTest { | ||
|
||
private TimelineDbRepository tRepository; | ||
private StorageDbRepository sRepository; | ||
private EventTypeDbRepository eRepository; | ||
|
||
public TimelineDbRepositoryTest() { | ||
super("zn_data.timeline", "zn_data.storage", "zn_data.event_type_schema", "zn_data.event_type"); | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
super.setUp(); | ||
this.tRepository = new TimelineDbRepository(template, mapper); | ||
this.sRepository = new StorageDbRepository(template, mapper); | ||
this.eRepository = new EventTypeDbRepository(template, mapper); | ||
} | ||
|
||
@Test | ||
public void testTimelineCreated() throws InternalNakadiException, DuplicatedEventTypeNameException { | ||
final Storage storage = sRepository.createStorage( | ||
StorageDbRepositoryTest.createStorage("default", "test", "path")); | ||
final EventType testEt = eRepository.saveEventType(TestUtils.buildDefaultEventType()); | ||
|
||
final Timeline timeline = createTimeline( | ||
storage, UUID.randomUUID(), 0, "test_topic", testEt.getName(), | ||
new Date(), null, null, null); | ||
|
||
tRepository.createTimeline(timeline); | ||
|
||
final Optional<Timeline> fromDb = tRepository.getTimeline(timeline.getId()); | ||
Assert.assertTrue(fromDb.isPresent()); | ||
Assert.assertFalse(fromDb.get() == timeline); | ||
Assert.assertEquals(timeline, fromDb.get()); | ||
} | ||
|
||
@Test | ||
public void testTimelineUpdate() throws InternalNakadiException, DuplicatedEventTypeNameException { | ||
final Storage storage = sRepository.createStorage( | ||
StorageDbRepositoryTest.createStorage("default", "test", "path")); | ||
final EventType testEt = eRepository.saveEventType(TestUtils.buildDefaultEventType()); | ||
|
||
final Timeline initial = tRepository.createTimeline(createTimeline( | ||
storage, UUID.randomUUID(), 0, "test_topic", testEt.getName(), | ||
new Date(), null, null, null)); | ||
|
||
final Timeline modified = tRepository.getTimeline(initial.getId()).get(); | ||
modified.setCreatedAt(new Date()); | ||
modified.setCleanupAt(new Date()); | ||
modified.setSwitchedAt(new Date()); | ||
final Timeline.KafkaStoragePosition pos = new Timeline.KafkaStoragePosition(); | ||
pos.setOffsets(LongStream.range(0L, 10L).mapToObj(Long::new).collect(Collectors.toList())); | ||
modified.setLatestPosition(pos); | ||
|
||
tRepository.updateTimelime(modified); | ||
final Timeline result = tRepository.getTimeline(modified.getId()).get(); | ||
|
||
Assert.assertEquals(modified, result); | ||
Assert.assertNotEquals(initial, result); | ||
} | ||
|
||
@Test(expected = DuplicateKeyException.class) | ||
public void testDuplicateOrderNotAllowed() throws InternalNakadiException, DuplicatedEventTypeNameException { | ||
final Storage storage = sRepository.createStorage( | ||
StorageDbRepositoryTest.createStorage("default", "test", "path")); | ||
final EventType testEt = eRepository.saveEventType(TestUtils.buildDefaultEventType()); | ||
|
||
tRepository.createTimeline(createTimeline( | ||
storage, UUID.randomUUID(), 0, "test_topic", testEt.getName(), | ||
new Date(), null, null, null)); | ||
tRepository.createTimeline(createTimeline( | ||
storage, UUID.randomUUID(), 0, "test_topic", testEt.getName(), | ||
new Date(), null, null, null)); | ||
} | ||
|
||
@Test | ||
public void testListTimelinesOrdered() throws InternalNakadiException, DuplicatedEventTypeNameException { | ||
final Storage storage = sRepository.createStorage( | ||
StorageDbRepositoryTest.createStorage("default", "test", "path")); | ||
final EventType testEt = eRepository.saveEventType(TestUtils.buildDefaultEventType()); | ||
final Timeline t1 = tRepository.createTimeline(createTimeline( | ||
storage, UUID.randomUUID(), 1, "test_topic", testEt.getName(), | ||
new Date(), null, null, null)); | ||
final Timeline t0 = tRepository.createTimeline(createTimeline( | ||
storage, UUID.randomUUID(), 0, "test_topic", testEt.getName(), | ||
new Date(), null, null, null)); | ||
|
||
final List<Timeline> testTimelines = tRepository.listTimelines(testEt.getName()); | ||
Assert.assertEquals(2, testTimelines.size()); | ||
Assert.assertEquals(t0, testTimelines.get(0)); | ||
Assert.assertEquals(t1, testTimelines.get(1)); | ||
} | ||
|
||
@Test | ||
public void testTimelineDeleted() throws InternalNakadiException, DuplicatedEventTypeNameException { | ||
final Storage storage = sRepository.createStorage( | ||
StorageDbRepositoryTest.createStorage("default", "test", "path")); | ||
final EventType testEt = eRepository.saveEventType(TestUtils.buildDefaultEventType()); | ||
final Timeline t1 = tRepository.createTimeline(createTimeline( | ||
storage, UUID.randomUUID(), 1, "test_topic", testEt.getName(), | ||
new Date(), null, null, null)); | ||
Assert.assertEquals(1, tRepository.listTimelines(testEt.getName()).size()); | ||
tRepository.deleteTimeline(t1.getId()); | ||
Assert.assertEquals(0, tRepository.listTimelines(testEt.getName()).size()); | ||
} | ||
|
||
private static Timeline createTimeline( | ||
final Storage storage, | ||
final UUID id, | ||
final int order, | ||
final String topic, | ||
final String eventType, | ||
final Date createdAt, | ||
final Date switchedAt, | ||
final Date cleanupAt, | ||
final Timeline.StoragePosition latestPosition) { | ||
final Timeline timeline = new Timeline(eventType, order, storage, topic, createdAt); | ||
timeline.setId(id); | ||
timeline.setSwitchedAt(switchedAt); | ||
timeline.setCleanupAt(cleanupAt); | ||
timeline.setLatestPosition(latestPosition); | ||
return timeline; | ||
} | ||
} |
Oops, something went wrong.