Search in sources :

Example 16 with KsqlObject

use of io.confluent.ksql.api.client.KsqlObject in project ksql by confluentinc.

the class ApplyMigrationCommandTest method shouldResetVariablesBetweenMigrations.

@SuppressWarnings("unchecked")
@Test
public void shouldResetVariablesBetweenMigrations() throws Exception {
    // Given:
    final Map<String, Object> variables = ImmutableMap.of("cat", "pat");
    command = PARSER.parse("-a");
    createMigrationFile(1, NAME, migrationsDir, "DEFINE cat='pat';");
    createMigrationFile(2, NAME, migrationsDir, "INSERT INTO FOO VALUES ('${cat}');");
    when(versionQueryResult.get()).thenReturn(ImmutableList.of());
    when(ksqlClient.getVariables()).thenReturn(ImmutableMap.of(), ImmutableMap.of(), variables, ImmutableMap.of());
    givenAppliedMigration(1, NAME, MigrationState.MIGRATED);
    // When:
    final int result = command.command(config, (cfg, headers) -> ksqlClient, migrationsDir, Clock.fixed(Instant.ofEpochMilli(1000), ZoneId.systemDefault()));
    // Then:
    assertThat(result, is(0));
    final InOrder inOrder = inOrder(ksqlClient);
    inOrder.verify(ksqlClient, times(2)).getVariables();
    inOrder.verify(ksqlClient).define("cat", "pat");
    inOrder.verify(ksqlClient).getVariables();
    inOrder.verify(ksqlClient).undefine("cat");
    inOrder.verify(ksqlClient).getVariables();
    inOrder.verify(ksqlClient).insertInto("`FOO`", new KsqlObject(ImmutableMap.of("`A`", "${cat}")));
    inOrder.verify(ksqlClient).close();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) KsqlObject(io.confluent.ksql.api.client.KsqlObject) KsqlObject(io.confluent.ksql.api.client.KsqlObject) Test(org.junit.Test)

Aggregations

KsqlObject (io.confluent.ksql.api.client.KsqlObject)16 Test (org.junit.Test)12 KsqlArray (io.confluent.ksql.api.client.KsqlArray)8 IntegrationTest (io.confluent.common.utils.IntegrationTest)6 KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)6 Row (io.confluent.ksql.api.client.Row)5 BigDecimal (java.math.BigDecimal)5 HashMap (java.util.HashMap)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 InOrder (org.mockito.InOrder)5 StreamedQueryResult (io.confluent.ksql.api.client.StreamedQueryResult)4 JsonArray (io.vertx.core.json.JsonArray)4 JsonObject (io.vertx.core.json.JsonObject)4 AcksPublisher (io.confluent.ksql.api.client.AcksPublisher)3 BatchedQueryResult (io.confluent.ksql.api.client.BatchedQueryResult)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Client (io.confluent.ksql.api.client.Client)2 ClientOptions (io.confluent.ksql.api.client.ClientOptions)2 ConnectorDescription (io.confluent.ksql.api.client.ConnectorDescription)2 ConnectorInfo (io.confluent.ksql.api.client.ConnectorInfo)2