Search in sources :

Example 91 with EventType

use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.

the class EventTypeCacheTestAT method onCreatedAddNewChildrenZNode.

@Test
public void onCreatedAddNewChildrenZNode() throws Exception {
    final EventTypeCache etc = new EventTypeCache(eventTypeRepository, timelineRepository, client, timelineSync);
    final EventType et = buildDefaultEventType();
    etc.created(et.getName());
    assertNotNull(client.get().checkExists().forPath("/nakadi/event_types/" + et.getName()));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 92 with EventType

use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.

the class EventTypeCacheTestAT method testGetTimelines.

@Test
public void testGetTimelines() throws Exception {
    final EventTypeCache etc = new RepositoriesConfig().eventTypeCache(client, eventTypeRepository, timelineRepository, timelineSync);
    final EventType et = buildDefaultEventType();
    Mockito.when(timelineRepository.listTimelinesOrdered(et.getName())).thenReturn(getMockedTimelines(et.getName()));
    Mockito.doReturn(et).when(eventTypeRepository).findByName(et.getName());
    final List<Timeline> timelines = etc.getTimelinesOrdered(et.getName());
    Assert.assertEquals(3, timelines.size());
}
Also used : RepositoriesConfig(org.zalando.nakadi.config.RepositoriesConfig) Timeline(org.zalando.nakadi.domain.Timeline) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 93 with EventType

use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.

the class EventTypeCacheTestAT method invalidateCacheOnUpdate.

@SuppressWarnings("unchecked")
@Test
public void invalidateCacheOnUpdate() throws Exception {
    final EventTypeCache etc = new RepositoriesConfig().eventTypeCache(client, eventTypeRepository, timelineRepository, timelineSync);
    final EventType et = buildDefaultEventType();
    Mockito.doReturn(et).when(eventTypeRepository).findByName(et.getName());
    etc.created(et.getName());
    etc.getEventType(et.getName());
    etc.updated(et.getName());
    executeWithRetry(() -> {
        try {
            etc.getEventType(et.getName());
            verify(eventTypeRepository, times(2)).findByName(et.getName());
        } catch (final Exception e) {
            fail();
        }
    }, new RetryForSpecifiedTimeStrategy<Void>(5000).withExceptionsThatForceRetry(AssertionError.class).withWaitBetweenEachTry(500));
}
Also used : RepositoriesConfig(org.zalando.nakadi.config.RepositoriesConfig) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 94 with EventType

use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.

the class EventTypeCacheTestAT method whenUpdatedSetChildrenZNodeValue.

@Test
public void whenUpdatedSetChildrenZNodeValue() throws Exception {
    final EventTypeCache etc = new EventTypeCache(eventTypeRepository, timelineRepository, client, timelineSync);
    final EventType et = buildDefaultEventType();
    client.get().create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath("/nakadi/event_types/" + et.getName(), "some-value".getBytes());
    etc.updated(et.getName());
    final byte[] data = client.get().getData().forPath("/nakadi/event_types/" + et.getName());
    assertThat(data, equalTo(new byte[0]));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 95 with EventType

use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.

the class EventTypeDbRepositoryTest method whenListExistingEventTypesAreListed.

@Test
public void whenListExistingEventTypesAreListed() throws NakadiException {
    final EventType eventType1 = buildDefaultEventType();
    final EventType eventType2 = buildDefaultEventType();
    repository.saveEventType(eventType1);
    repository.saveEventType(eventType2);
    final List<EventType> eventTypes = repository.list().stream().filter(et -> et.getName() != null).filter(et -> et.getName().equals(eventType1.getName()) || et.getName().equals(eventType2.getName())).collect(Collectors.toList());
    assertThat(eventTypes, hasSize(2));
}
Also used : EventCategory(org.zalando.nakadi.domain.EventCategory) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) DuplicatedEventTypeNameException(org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException) Test(org.junit.Test) IOException(java.io.IOException) NakadiException(org.zalando.nakadi.exceptions.NakadiException) TestUtils(org.zalando.nakadi.utils.TestUtils) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) Collectors(java.util.stream.Collectors) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) Version(org.zalando.nakadi.domain.Version) EventTypeSchema(org.zalando.nakadi.domain.EventTypeSchema) List(java.util.List) EventTypeRepository(org.zalando.nakadi.repository.EventTypeRepository) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Matchers.hasSize(org.hamcrest.Matchers.hasSize) SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Test(org.junit.Test)

Aggregations

EventType (org.zalando.nakadi.domain.EventType)216 Test (org.junit.Test)183 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)138 JSONObject (org.json.JSONObject)40 Problem (org.zalando.problem.Problem)21 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)18 Matchers.containsString (org.hamcrest.Matchers.containsString)17 JSONArray (org.json.JSONArray)17 EventPublishResult (org.zalando.nakadi.domain.EventPublishResult)17 TestUtils.invalidProblem (org.zalando.nakadi.utils.TestUtils.invalidProblem)17 ThrowableProblem (org.zalando.problem.ThrowableProblem)17 Timeline (org.zalando.nakadi.domain.Timeline)16 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)14 EventTypeTestBuilder (org.zalando.nakadi.utils.EventTypeTestBuilder)14 BatchItem (org.zalando.nakadi.domain.BatchItem)12 TestUtils.resourceAsString (org.zalando.nakadi.utils.TestUtils.resourceAsString)12 List (java.util.List)11 Subscription (org.zalando.nakadi.domain.Subscription)11 TestUtils.createBatchItem (org.zalando.nakadi.utils.TestUtils.createBatchItem)11 Collectors (java.util.stream.Collectors)9