Search in sources :

Example 6 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class KsLocatorTest method shouldReturnRemoteOwnerForDifferentHost.

@Test
public void shouldReturnRemoteOwnerForDifferentHost() {
    // Given:
    final HostInfo localHostInfo = new HostInfo("different", LOCAL_HOST_URL.getPort());
    final KsqlHostInfo localHost = locator.asKsqlHost(localHostInfo);
    getActiveAndStandbyMetadata(localHostInfo);
    when(activeFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
    when(livenessFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
    // When:
    final List<KsqlPartitionLocation> result = locator.locate(ImmutableList.of(KEY), routingOptions, routingFilterFactoryActive, false);
    // Then:
    List<KsqlNode> nodeList = result.get(0).getNodes();
    assertThat(nodeList.stream().findFirst().map(KsqlNode::isLocal), is(Optional.of(false)));
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) KsqlNode(io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Test(org.junit.Test)

Example 7 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class KsLocatorTest method shouldReturnRemoteOwnerForDifferentPortOnLocalHost.

@Test
public void shouldReturnRemoteOwnerForDifferentPortOnLocalHost() {
    // Given:
    final HostInfo localHostInfo = new HostInfo("LOCALhost", LOCAL_HOST_URL.getPort() + 1);
    final KsqlHostInfo localHost = locator.asKsqlHost(localHostInfo);
    getActiveAndStandbyMetadata(localHostInfo);
    when(activeFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
    when(livenessFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
    // When:
    final List<KsqlPartitionLocation> result = locator.locate(ImmutableList.of(KEY), routingOptions, routingFilterFactoryActive, false);
    // Then:
    List<KsqlNode> nodeList = result.get(0).getNodes();
    assertThat(nodeList.stream().findFirst().map(KsqlNode::isLocal), is(Optional.of(false)));
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) KsqlNode(io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Test(org.junit.Test)

Example 8 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class TestExecutorUtil method execute.

/**
 * @param srClient if supplied, then schemas can be inferred from the schema registry.
 * @return a list of persistent queries that should be run by the test executor, if a query was
 *         replaced via a CREATE OR REPLACE statement it will only appear once in the output list
 */
@SuppressWarnings("OptionalGetWithoutIsPresent")
private static List<PersistentQueryAndSources> execute(final KsqlEngine engine, final TestCase testCase, final KsqlConfig ksqlConfig, final ServiceContext serviceContext, final Optional<SchemaRegistryClient> srClient, final StubKafkaService stubKafkaService, final TestExecutionListener listener) {
    final Map<QueryId, PersistentQueryAndSources> queries = new LinkedHashMap<>();
    int idx = 0;
    final Iterator<PlannedStatement> plans = planTestCase(engine, testCase, ksqlConfig, serviceContext, srClient, stubKafkaService);
    try {
        while (plans.hasNext()) {
            ++idx;
            final PlannedStatement planned = plans.next();
            if (planned.insertValues.isPresent()) {
                final ConfiguredStatement<InsertValues> insertValues = planned.insertValues.get();
                final SessionProperties sessionProperties = new SessionProperties(insertValues.getSessionConfig().getOverrides(), new KsqlHostInfo("host", 50), buildUrl(), false);
                StubInsertValuesExecutor.of(stubKafkaService).execute(insertValues, sessionProperties, engine, engine.getServiceContext());
                continue;
            }
            final ConfiguredKsqlPlan plan = planned.plan.orElseThrow(IllegalStateException::new);
            listener.acceptPlan(plan);
            final ExecuteResultAndSources result = executePlan(engine, plan);
            if (!result.getSources().isPresent()) {
                continue;
            }
            final PersistentQueryMetadata query = (PersistentQueryMetadata) result.getExecuteResult().getQuery().get();
            listener.acceptQuery(query);
            queries.put(query.getQueryId(), new PersistentQueryAndSources(query, result.getSources().get()));
        }
        return ImmutableList.copyOf(queries.values());
    } catch (final KsqlStatementException e) {
        if (testCase.expectedException().isPresent() && plans.hasNext()) {
            throw new AssertionError("Only the last statement in a negative test should fail. " + "Yet in this case statement " + idx + " failed.", e);
        }
        throw e;
    }
}
Also used : ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) QueryId(io.confluent.ksql.query.QueryId) LinkedHashMap(java.util.LinkedHashMap) SessionProperties(io.confluent.ksql.rest.SessionProperties) InsertValues(io.confluent.ksql.parser.tree.InsertValues) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata)

Example 9 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class LivenessFilterTest method setUp.

@Before
public void setUp() {
    activeHost = new KsqlHostInfo("activeHost", 2345);
    standByHost1 = new KsqlHostInfo("standby1", 1234);
    standByHost2 = new KsqlHostInfo("standby2", 5678);
    Optional<HeartbeatAgent> optionalHeartbeatAgent = Optional.of(heartbeatAgent);
    livenessFilter = new LivenessFilter(optionalHeartbeatAgent);
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Before(org.junit.Before)

Example 10 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class HeartbeatAgentTest method setUp.

@Before
public void setUp() {
    localHostInfo = new HostInfo("localhost", 8088);
    remoteHostInfo = new HostInfo("localhost", 8089);
    localHost = new KsqlHostInfo("localhost", 8088);
    remoteHost = new KsqlHostInfo("localhost", 8089);
    Builder builder = HeartbeatAgent.builder();
    heartbeatAgent = builder.heartbeatSendInterval(1).heartbeatMissedThreshold(2).addHostStatusListener(hostStatusListener).build(ksqlEngine, serviceContext);
    heartbeatAgent.setLocalAddress(LOCALHOST_URL);
    hostsStatus = ImmutableMap.of(localHost, new HostStatus(true, 0L), remoteHost, new HostStatus(true, 0L));
    allMetadata0 = ImmutableList.of(streamsMetadata0);
    allMetadata1 = ImmutableList.of(streamsMetadata1);
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Builder(io.confluent.ksql.rest.server.HeartbeatAgent.Builder) HostStatus(io.confluent.ksql.util.HostStatus) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Before(org.junit.Before)

Aggregations

KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)19 HostInfo (org.apache.kafka.streams.state.HostInfo)9 Test (org.junit.Test)7 KsqlPartitionLocation (io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation)6 KsqlNode (io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode)5 Before (org.junit.Before)4 HostStatus (io.confluent.ksql.util.HostStatus)3 RoutingFilter (io.confluent.ksql.execution.streams.RoutingFilter)2 DataSource (io.confluent.ksql.metastore.model.DataSource)2 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)2 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)2 List (java.util.List)2 Optional (java.util.Optional)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 RoutingOptions (io.confluent.ksql.execution.streams.RoutingOptions)1