Search in sources :

Example 1 with SnowflakeCloseSourceOrSink

use of org.talend.components.snowflake.runtime.SnowflakeCloseSourceOrSink in project components by Talend.

the class TSnowflakeCloseDefinitionTest method testGetRuntime.

/**
 * Check {@link TSnowflakeCloseDefinition#getRuntimeInfo(ExecutionEngine, ComponentProperties, ConnectorTopology)} returns instance of {@link SnowflakeCloseSourceOrSink}
 */
@Test
public void testGetRuntime() {
    RuntimeInfo runtimeInfo = snowflakeCloseDefinition.getRuntimeInfo(ExecutionEngine.DI, null, ConnectorTopology.NONE);
    SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, snowflakeCloseDefinition.getClass().getClassLoader());
    SourceOrSink source = (SourceOrSink) sandboxedInstance.getInstance();
    assertThat(source, is(instanceOf(SnowflakeCloseSourceOrSink.class)));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) SnowflakeCloseSourceOrSink(org.talend.components.snowflake.runtime.SnowflakeCloseSourceOrSink) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Test(org.junit.Test)

Example 2 with SnowflakeCloseSourceOrSink

use of org.talend.components.snowflake.runtime.SnowflakeCloseSourceOrSink in project components by Talend.

the class SnowflakeReadersTestIT method testCloseExistingConnection.

@Test
public void testCloseExistingConnection() throws Throwable {
    SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) getComponentService().getComponentProperties(TSnowflakeConnectionDefinition.COMPONENT_NAME);
    setupProps(connProps);
    final String currentComponentName = TSnowflakeConnectionDefinition.COMPONENT_NAME + "_1";
    RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return currentComponentName;
        }
    };
    SnowflakeSourceOrSink snowflakeSourceOrSink = new SnowflakeSourceOrSink();
    snowflakeSourceOrSink.initialize(connContainer, connProps);
    assertEquals(ValidationResult.Result.OK, snowflakeSourceOrSink.validate(connContainer).getStatus());
    TSnowflakeCloseProperties closeProps = (TSnowflakeCloseProperties) getComponentService().getComponentProperties(TSnowflakeCloseDefinition.COMPONENT_NAME);
    closeProps.referencedComponent.componentInstanceId.setValue(currentComponentName);
    SnowflakeCloseSourceOrSink snowflakeCloseSourceOrSink = new SnowflakeCloseSourceOrSink();
    snowflakeCloseSourceOrSink.initialize(connContainer, closeProps);
    assertEquals(ValidationResult.Result.OK, snowflakeCloseSourceOrSink.validate(connContainer).getStatus());
}
Also used : DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) SnowflakeSourceOrSink(org.talend.components.snowflake.runtime.SnowflakeSourceOrSink) SnowflakeCloseSourceOrSink(org.talend.components.snowflake.runtime.SnowflakeCloseSourceOrSink) TSnowflakeCloseProperties(org.talend.components.snowflake.tsnowflakeclose.TSnowflakeCloseProperties) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) Matchers.containsString(org.hamcrest.Matchers.containsString) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 3 with SnowflakeCloseSourceOrSink

use of org.talend.components.snowflake.runtime.SnowflakeCloseSourceOrSink in project components by Talend.

the class SnowflakeReadersTestIT method testSameConnectionForSeveralReaders.

@Test(expected = IOException.class)
public void testSameConnectionForSeveralReaders() throws Throwable {
    SnowflakeConnectionProperties connProps = (SnowflakeConnectionProperties) getComponentService().getComponentProperties(TSnowflakeConnectionDefinition.COMPONENT_NAME);
    setupProps(connProps);
    final String currentComponentName = TSnowflakeConnectionDefinition.COMPONENT_NAME + "_1";
    RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return currentComponentName;
        }
    };
    SnowflakeSourceOrSink SnowflakeSourceOrSink = new SnowflakeSourceOrSink();
    SnowflakeSourceOrSink.initialize(connContainer, connProps);
    assertEquals(ValidationResult.Result.OK, SnowflakeSourceOrSink.validate(connContainer).getStatus());
    TSnowflakeOutputProperties props = (TSnowflakeOutputProperties) getComponentService().getComponentProperties(TSnowflakeOutputDefinition.COMPONENT_NAME);
    setupProps(props.getConnectionProperties());
    setupTableWithStaticValues(props);
    props.connection.referencedComponent.componentInstanceId.setValue(currentComponentName);
    List<IndexedRecord> rows = readRows(props, connContainer);
    assertEquals(100, rows.size());
    // Read second time with the same properties but with new reader.
    rows = readRows(props, connContainer);
    assertEquals(100, rows.size());
    TSnowflakeCloseProperties closeProps = (TSnowflakeCloseProperties) getComponentService().getComponentProperties(TSnowflakeCloseDefinition.COMPONENT_NAME);
    closeProps.referencedComponent.componentInstanceId.setValue(currentComponentName);
    SnowflakeCloseSourceOrSink snowflakeCloseSourceOrSink = new SnowflakeCloseSourceOrSink();
    snowflakeCloseSourceOrSink.initialize(connContainer, closeProps);
    assertEquals(ValidationResult.Result.OK, snowflakeCloseSourceOrSink.validate(connContainer).getStatus());
    // After close, exception should be thrown by the reader, if we try to read with the same connection.
    rows = readRows(props, connContainer);
}
Also used : TSnowflakeOutputProperties(org.talend.components.snowflake.tsnowflakeoutput.TSnowflakeOutputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) SnowflakeSourceOrSink(org.talend.components.snowflake.runtime.SnowflakeSourceOrSink) SnowflakeCloseSourceOrSink(org.talend.components.snowflake.runtime.SnowflakeCloseSourceOrSink) TSnowflakeCloseProperties(org.talend.components.snowflake.tsnowflakeclose.TSnowflakeCloseProperties) SnowflakeConnectionProperties(org.talend.components.snowflake.SnowflakeConnectionProperties) Matchers.containsString(org.hamcrest.Matchers.containsString) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 SnowflakeCloseSourceOrSink (org.talend.components.snowflake.runtime.SnowflakeCloseSourceOrSink)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)2 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)2 SnowflakeConnectionProperties (org.talend.components.snowflake.SnowflakeConnectionProperties)2 SnowflakeSourceOrSink (org.talend.components.snowflake.runtime.SnowflakeSourceOrSink)2 TSnowflakeCloseProperties (org.talend.components.snowflake.tsnowflakeclose.TSnowflakeCloseProperties)2 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 SourceOrSink (org.talend.components.api.component.runtime.SourceOrSink)1 TSnowflakeOutputProperties (org.talend.components.snowflake.tsnowflakeoutput.TSnowflakeOutputProperties)1 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)1 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)1