Search in sources :

Example 1 with Version

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

the class SchemaEvolutionServiceTest method compatibilityModeMigrationAllowedChanges.

@Test
public void compatibilityModeMigrationAllowedChanges() throws Exception {
    final EventTypeTestBuilder builder = EventTypeTestBuilder.builder().compatibilityMode(CompatibilityMode.FORWARD);
    final EventType oldEventType = builder.build();
    final EventType newEventType = builder.compatibilityMode(CompatibilityMode.COMPATIBLE).build();
    Mockito.doReturn(Optional.empty()).when(evolutionConstraint).validate(oldEventType, newEventType);
    final List<SchemaChange.Type> allowedChanges = Lists.newArrayList(DESCRIPTION_CHANGED, TITLE_CHANGED, PROPERTIES_ADDED, REQUIRED_ARRAY_EXTENDED, ADDITIONAL_PROPERTIES_CHANGED, ADDITIONAL_ITEMS_CHANGED);
    final List<SchemaChange.Type> notAllowedChanges = Lists.newArrayList(ID_CHANGED, SCHEMA_REMOVED, TYPE_CHANGED, NUMBER_OF_ITEMS_CHANGED, PROPERTY_REMOVED, DEPENDENCY_ARRAY_CHANGED, DEPENDENCY_SCHEMA_CHANGED, COMPOSITION_METHOD_CHANGED, ATTRIBUTE_VALUE_CHANGED, ENUM_ARRAY_CHANGED, SUB_SCHEMA_CHANGED, DEPENDENCY_SCHEMA_REMOVED, REQUIRED_ARRAY_CHANGED);
    allowedChanges.forEach(changeType -> {
        Mockito.doReturn(MINOR).when(forwardChanges).get(any());
        Mockito.doReturn(Lists.newArrayList(new SchemaChange(changeType, "#/"))).when(schemaDiff).collectChanges(any(), any());
        final EventType eventType;
        try {
            eventType = service.evolve(oldEventType, newEventType);
            assertThat(eventType.getSchema().getVersion(), is(equalTo(new Version("1.1.0"))));
        } catch (final InvalidEventTypeException e) {
            fail();
        }
    });
    notAllowedChanges.forEach(changeType -> {
        Mockito.doReturn(Lists.newArrayList(new SchemaChange(changeType, "#/"))).when(schemaDiff).collectChanges(any(), any());
        try {
            service.evolve(oldEventType, newEventType);
            fail();
        } catch (final InvalidEventTypeException e) {
        }
    });
}
Also used : EventType(org.zalando.nakadi.domain.EventType) InvalidEventTypeException(org.zalando.nakadi.exceptions.InvalidEventTypeException) EventType(org.zalando.nakadi.domain.EventType) Version(org.zalando.nakadi.domain.Version) SchemaChange(org.zalando.nakadi.domain.SchemaChange) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) Test(org.junit.Test)

Example 2 with Version

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

the class SchemaEvolutionServiceTest method whenIncompatibleModeAllowMajorChanges.

@Test
public void whenIncompatibleModeAllowMajorChanges() throws Exception {
    final EventTypeTestBuilder builder = EventTypeTestBuilder.builder().compatibilityMode(CompatibilityMode.NONE);
    final EventType oldEventType = builder.build();
    final EventType newEventType = builder.build();
    Mockito.doReturn(Optional.empty()).when(evolutionConstraint).validate(oldEventType, newEventType);
    Mockito.doReturn(MAJOR).when(forwardChanges).get(any());
    Mockito.doReturn(Lists.newArrayList(new SchemaChange(TITLE_CHANGED, "#/"))).when(schemaDiff).collectChanges(any(), any());
    final EventType eventType = service.evolve(oldEventType, newEventType);
    assertThat(eventType.getSchema().getVersion(), is(equalTo(new Version("2.0.0"))));
    verify(evolutionConstraint).validate(oldEventType, newEventType);
}
Also used : EventType(org.zalando.nakadi.domain.EventType) Version(org.zalando.nakadi.domain.Version) SchemaChange(org.zalando.nakadi.domain.SchemaChange) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) Test(org.junit.Test)

Example 3 with Version

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

the class SchemaEvolutionServiceTest method whenPatchChangesBumpVersion.

@Test
public void whenPatchChangesBumpVersion() throws Exception {
    final EventTypeTestBuilder builder = EventTypeTestBuilder.builder();
    final EventType oldEventType = builder.build();
    final EventType newEventType = builder.build();
    Mockito.doReturn(Optional.empty()).when(evolutionConstraint).validate(oldEventType, newEventType);
    Mockito.doReturn(PATCH).when(compatibleChanges).get(any());
    Mockito.doReturn(Lists.newArrayList(new SchemaChange(TITLE_CHANGED, "#/"))).when(schemaDiff).collectChanges(any(), any());
    final EventType eventType = service.evolve(oldEventType, newEventType);
    assertThat(eventType.getSchema().getVersion(), is(equalTo(new Version("1.0.1"))));
    verify(evolutionConstraint).validate(oldEventType, newEventType);
}
Also used : EventType(org.zalando.nakadi.domain.EventType) Version(org.zalando.nakadi.domain.Version) SchemaChange(org.zalando.nakadi.domain.SchemaChange) EventTypeTestBuilder(org.zalando.nakadi.utils.EventTypeTestBuilder) Test(org.junit.Test)

Example 4 with Version

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

the class EventTypeDbRepositoryTest method whenUpdateDifferentSchemaVersionThenInsertIt.

@Test
public void whenUpdateDifferentSchemaVersionThenInsertIt() throws NakadiException, IOException {
    final EventType eventType = buildDefaultEventType();
    repository.saveEventType(eventType);
    eventType.getSchema().setVersion(new Version("1.1.0"));
    repository.update(eventType);
    final int rows = template.queryForObject("SELECT count(*) FROM zn_data.event_type_schema where ets_event_type_name=?", Integer.class, eventType.getName());
    assertThat("Number of rows should increase", rows, equalTo(2));
}
Also used : EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Version(org.zalando.nakadi.domain.Version) Test(org.junit.Test)

Example 5 with Version

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

the class SchemaRepositoryTest method whenListVersionsListedOrdered.

@Test
public void whenListVersionsListedOrdered() throws Exception {
    final String name = randomUUID();
    buildEventWithMultipleSchemas(name);
    final List<EventTypeSchema> schemas = repository.getSchemas(name, 0, 3);
    Assert.assertEquals(3, schemas.size());
    Assert.assertEquals(new Version("10.0.0"), schemas.get(0).getVersion());
    Assert.assertEquals(new Version("2.10.3"), schemas.get(1).getVersion());
    Assert.assertEquals(new Version("1.0.2"), schemas.get(2).getVersion());
    final int count = repository.getSchemasCount(name);
    Assert.assertEquals(3, count);
}
Also used : EventTypeSchema(org.zalando.nakadi.domain.EventTypeSchema) Version(org.zalando.nakadi.domain.Version) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 Version (org.zalando.nakadi.domain.Version)8 EventType (org.zalando.nakadi.domain.EventType)7 EventTypeTestBuilder (org.zalando.nakadi.utils.EventTypeTestBuilder)6 SchemaChange (org.zalando.nakadi.domain.SchemaChange)4 EventTypeSchema (org.zalando.nakadi.domain.EventTypeSchema)1 InvalidEventTypeException (org.zalando.nakadi.exceptions.InvalidEventTypeException)1 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)1