Search in sources :

Example 6 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class TableResolverImplTest method when_createsDuplicateMappingWithIfNotExists_then_succeeds.

@Test
public void when_createsDuplicateMappingWithIfNotExists_then_succeeds() {
    // given
    Mapping mapping = mapping();
    given(connectorCache.forType(mapping.type())).willReturn(connector);
    given(connector.resolveAndValidateFields(nodeEngine, mapping.options(), mapping.fields())).willReturn(singletonList(new MappingField("field_name", INT)));
    given(tableStorage.putIfAbsent(eq(mapping.name()), isA(Mapping.class))).willReturn(false);
    // when
    catalog.createMapping(mapping, false, true);
    // then
    verifyNoInteractions(listener);
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) MappingField(com.hazelcast.sql.impl.schema.MappingField) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class TableResolverImplTest method when_replacesMapping_then_succeeds.

@Test
public void when_replacesMapping_then_succeeds() {
    // given
    Mapping mapping = mapping();
    given(connectorCache.forType(mapping.type())).willReturn(connector);
    given(connector.resolveAndValidateFields(nodeEngine, mapping.options(), mapping.fields())).willReturn(singletonList(new MappingField("field_name", INT)));
    // when
    catalog.createMapping(mapping, true, false);
    // then
    verify(tableStorage).put(eq(mapping.name()), isA(Mapping.class));
    verify(listener).onTableChanged();
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) MappingField(com.hazelcast.sql.impl.schema.MappingField) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class TableResolverImplTest method when_createsInvalidMapping_then_throws.

// region mapping storage tests
@Test
public void when_createsInvalidMapping_then_throws() {
    // given
    Mapping mapping = mapping();
    given(connectorCache.forType(mapping.type())).willReturn(connector);
    given(connector.resolveAndValidateFields(nodeEngine, mapping.options(), mapping.fields())).willThrow(new RuntimeException("expected test exception"));
    // when
    // then
    assertThatThrownBy(() -> catalog.createMapping(mapping, true, true)).hasMessageContaining("expected test exception");
    verify(tableStorage, never()).putIfAbsent(anyString(), (Mapping) any());
    verify(tableStorage, never()).put(anyString(), (Mapping) any());
    verifyNoInteractions(listener);
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class TableResolverImplTest method when_createsDuplicateMapping_then_throws.

@Test
public void when_createsDuplicateMapping_then_throws() {
    // given
    Mapping mapping = mapping();
    given(connectorCache.forType(mapping.type())).willReturn(connector);
    given(connector.resolveAndValidateFields(nodeEngine, mapping.options(), mapping.fields())).willReturn(singletonList(new MappingField("field_name", INT)));
    given(tableStorage.putIfAbsent(eq(mapping.name()), isA(Mapping.class))).willReturn(false);
    // when
    // then
    assertThatThrownBy(() -> catalog.createMapping(mapping, false, false)).isInstanceOf(QueryException.class).hasMessageContaining("Mapping or view already exists: name");
    verifyNoInteractions(listener);
}
Also used : QueryException(com.hazelcast.sql.impl.QueryException) Mapping(com.hazelcast.sql.impl.schema.Mapping) MappingField(com.hazelcast.sql.impl.schema.MappingField) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with Mapping

use of com.hazelcast.sql.impl.schema.Mapping in project hazelcast by hazelcast.

the class MappingColumnsTableTest method test_rows.

@Test
public void test_rows() {
    // given
    Mapping mapping = new Mapping("table-name", "table-external-name", "table-type", singletonList(new MappingField("table-field-name", INT, "table-field-external-name")), emptyMap());
    View view = new View("view-name", "select * from table-name", false, singletonList("col1"), singletonList(INT));
    MappingColumnsTable mappingColumnsTable = new MappingColumnsTable("catalog", null, "schema", singletonList(mapping), singletonList(view));
    // when
    List<Object[]> rows = mappingColumnsTable.rows();
    // then
    assertThat(rows).containsExactlyInAnyOrder(new Object[] { "catalog", "schema", "table-name", "table-field-name", "table-field-external-name", 1, "true", "INTEGER" }, new Object[] { "catalog", "schema", "view-name", "col1", null, 1, "true", "INTEGER" });
}
Also used : Mapping(com.hazelcast.sql.impl.schema.Mapping) MappingField(com.hazelcast.sql.impl.schema.MappingField) View(com.hazelcast.sql.impl.schema.view.View) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Mapping (com.hazelcast.sql.impl.schema.Mapping)20 MappingField (com.hazelcast.sql.impl.schema.MappingField)11 Test (org.junit.Test)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 View (com.hazelcast.sql.impl.schema.view.View)6 ArrayList (java.util.ArrayList)4 NodeEngine (com.hazelcast.spi.impl.NodeEngine)3 MemberSelectors (com.hazelcast.cluster.memberselector.MemberSelectors)2 EntryEvent (com.hazelcast.core.EntryEvent)2 CreateMappingPlan (com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateMappingPlan)2 SqlCreateMapping (com.hazelcast.jet.sql.impl.parse.SqlCreateMapping)2 ILogger (com.hazelcast.logging.ILogger)2 QueryException (com.hazelcast.sql.impl.QueryException)2 List (java.util.List)2 Objects (java.util.Objects)2 Collectors.toList (java.util.stream.Collectors.toList)2 Nullable (javax.annotation.Nullable)2 Address (com.hazelcast.cluster.Address)1 Member (com.hazelcast.cluster.Member)1