use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.
the class CachingEventTypeRepository method removeEventType.
@Override
public void removeEventType(final String name) throws InternalNakadiException, NoSuchEventTypeException {
final EventType original = this.repository.findByName(name);
this.repository.removeEventType(name);
try {
this.cache.removed(name);
} catch (Exception e) {
LOG.error("Failed to remove entry from cache '" + name + "'");
try {
this.repository.saveEventType(original);
} catch (DuplicatedEventTypeNameException e1) {
LOG.error("Failed to rollback db removal", e);
}
throw new InternalNakadiException("Failed to remove event type", e);
}
}
use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.
the class EventTypeDbRepository method saveEventType.
@Override
@Transactional
public EventType saveEventType(final EventTypeBase eventTypeBase) throws InternalNakadiException, DuplicatedEventTypeNameException {
try {
final DateTime now = new DateTime(DateTimeZone.UTC);
final EventType eventType = new EventType(eventTypeBase, "1.0.0", now, now);
jdbcTemplate.update("INSERT INTO zn_data.event_type (et_name, et_event_type_object) VALUES (?, ?::jsonb)", eventTypeBase.getName(), jsonMapper.writer().writeValueAsString(eventType));
insertEventTypeSchema(eventType);
return eventType;
} catch (final JsonProcessingException e) {
throw new InternalNakadiException("Serialization problem during persistence of event type", e);
} catch (final DuplicateKeyException e) {
throw new DuplicatedEventTypeNameException("EventType " + eventTypeBase.getName() + " already exists.", e);
}
}
use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.
the class CursorsServiceAT method before.
@Before
public void before() throws Exception {
sid = randomUUID();
streamId = randomUUID();
etName = randomValidEventTypeName();
topic = randomUUID();
cursorConverter = mock(CursorConverter.class);
testCursors = ImmutableList.of(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P1, NEW_OFFSET));
final EventType eventType = mock(EventType.class);
when(eventType.getName()).thenReturn(etName);
final ZooKeeperHolder zkHolder = mock(ZooKeeperHolder.class);
when(zkHolder.get()).thenReturn(CURATOR);
final TopicRepository topicRepository = mock(TopicRepository.class);
final TimelineService timelineService = mock(TimelineService.class);
when(timelineService.getTopicRepository((Timeline) any())).thenReturn(topicRepository);
timeline = buildTimeline(etName, topic, CREATED_AT);
when(timelineService.getActiveTimeline(any(EventType.class))).thenReturn(timeline);
final Subscription subscription = mock(Subscription.class);
when(subscription.getId()).thenReturn(sid);
when(subscription.getEventTypes()).thenReturn(ImmutableSet.of(etName));
final SubscriptionDbRepository subscriptionRepo = mock(SubscriptionDbRepository.class);
when(subscriptionRepo.getSubscription(sid)).thenReturn(subscription);
final SubscriptionClientFactory zkSubscriptionFactory = new SubscriptionClientFactory(zkHolder, MAPPER);
uuidGenerator = mock(UUIDGenerator.class);
when(uuidGenerator.isUUID(any())).thenReturn(true);
cursorsService = new CursorsService(subscriptionRepo, null, mock(NakadiSettings.class), zkSubscriptionFactory, cursorConverter, uuidGenerator, null);
// Register cursors in converter
registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P1, NEW_OFFSET));
registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P1, OLD_OFFSET));
registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P2, NEW_OFFSET));
registerNakadiCursor(NakadiCursor.of(buildTimeline(etName, topic, CREATED_AT), P2, OLD_OFFSET));
// bootstrap data in ZK
CURATOR.create().creatingParentsIfNeeded().forPath(offsetPath(P1), OLD_OFFSET.getBytes(UTF_8));
CURATOR.create().creatingParentsIfNeeded().forPath(offsetPath(P2), OLD_OFFSET.getBytes(UTF_8));
CURATOR.create().creatingParentsIfNeeded().forPath(sessionPath(streamId));
}
use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.
the class EventStreamReadingAT method whenMemoryOverflowEventsDumped.
@Test(timeout = 10000)
public void whenMemoryOverflowEventsDumped() throws IOException {
// Create event type
final EventType loadEt = EventTypeTestBuilder.builder().defaultStatistic(new EventTypeStatistics(PARTITIONS_NUM, PARTITIONS_NUM)).build();
NakadiTestUtils.createEventTypeInNakadi(loadEt);
// Publish events to event type, that are not fitting memory
final String evt = "{\"foo\":\"barbarbar\"}";
final int eventCount = 2 * (10000 / evt.length());
NakadiTestUtils.publishEvents(loadEt.getName(), eventCount, i -> evt);
// Configure streaming so it will:(more than 10s and batch_limit
// - definitely wait for more than test timeout (10s)
// - collect batch, which size is greater than events published to this event type
final String url = RestAssured.baseURI + ":" + RestAssured.port + createStreamEndpointUrl(loadEt.getName()) + "?batch_limit=" + (10 * eventCount) + "&stream_limit=" + (10 * eventCount) + "&batch_flush_timeout=11" + "&stream_timeout=11";
final HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
// Start from the begin.
connection.setRequestProperty("X-Nakadi-Cursors", "[" + IntStream.range(0, PARTITIONS_NUM).mapToObj(i -> "{\"partition\": \"" + i + "\",\"offset\":\"begin\"}").collect(Collectors.joining(",")) + "]");
Assert.assertEquals(HttpServletResponse.SC_OK, connection.getResponseCode());
final InputStream inputStream = connection.getInputStream();
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
final String line = reader.readLine();
Assert.assertNotNull(line);
// If we read at least one line, than it means, that we were able to read data before test timeout reached.
}
use of org.zalando.nakadi.domain.EventType in project nakadi by zalando.
the class EventTypeAT method whenPUTValidEventTypeThenOK.
@Test
public void whenPUTValidEventTypeThenOK() throws Exception {
final EventType eventType = buildDefaultEventType();
final String body = MAPPER.writer().writeValueAsString(eventType);
given().body(body).header("accept", "application/json").contentType(JSON).post(ENDPOINT).then().body(equalTo("")).statusCode(HttpStatus.SC_CREATED);
final EventType retrievedEventType = MAPPER.readValue(given().header("accept", "application/json").get(ENDPOINT + "/" + eventType.getName()).getBody().asString(), EventType.class);
final String updateBody = MAPPER.writer().writeValueAsString(retrievedEventType);
given().body(updateBody).header("accept", "application/json").contentType(JSON).when().put(ENDPOINT + "/" + eventType.getName()).then().body(equalTo("")).statusCode(HttpStatus.SC_OK);
}
Aggregations