use of io.confluent.ksql.test.TestFrameworkException in project ksql by confluentinc.
the class TestFileContext method getLineNumber.
private int getLineNumber(final String testName) {
final Pattern pattern = Pattern.compile(".*\"name\"\\s*:\\s*\"" + Pattern.quote(testName) + "\".*");
int lineNumber = 0;
for (final String line : lines) {
lineNumber++;
if (pattern.matcher(line).matches()) {
return lineNumber;
}
}
throw new TestFrameworkException("Can't find test in test file" + System.lineSeparator() + "test: " + testName + System.lineSeparator() + "file: " + testPath);
}
use of io.confluent.ksql.test.TestFrameworkException in project ksql by confluentinc.
the class JsonTestLoader method loadTestPathsFromDirectory.
private List<Path> loadTestPathsFromDirectory() {
final InputStream s = JsonTestLoader.class.getClassLoader().getResourceAsStream(testDir.toString());
if (s == null) {
throw new TestFrameworkException("Test directory not found: " + testDir);
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(s, UTF_8))) {
final List<Path> tests = new ArrayList<>();
String test;
while ((test = reader.readLine()) != null) {
if (test.endsWith(".json")) {
tests.add(testDir.resolve(test));
}
}
return tests;
} catch (final IOException e) {
throw new TestFrameworkException("Failed to read test dir: " + testDir, e);
}
}
use of io.confluent.ksql.test.TestFrameworkException in project ksql by confluentinc.
the class TopicInfoCache method load.
private TopicInfo load(final String topicName) {
try {
final Optional<InternalTopic> internalTopic = INTERNAL_TOPIC_PATTERNS.stream().map(e -> e.match(topicName)).filter(Optional::isPresent).map(Optional::get).findFirst();
if (internalTopic.isPresent()) {
// Internal topic:
final QueryId queryId = internalTopic.get().queryId();
final PersistentQueryMetadata query = ksqlEngine.getPersistentQuery(queryId).orElseThrow(() -> new TestFrameworkException("Unknown queryId for internal topic: " + queryId));
final QuerySchemas.MultiSchemaInfo schemasInfo = query.getQuerySchemas().getTopicInfo(topicName);
final Set<KeyFormat> keyFormats = schemasInfo.getKeyFormats();
final Set<ValueFormat> valueFormats = schemasInfo.getValueFormats();
// foreign key joins once the above github issue is implemented.
if (keyFormats.size() != 1) {
final String result = keyFormats.size() == 0 ? "Zero" : "Multiple";
throw new Exception(result + " key formats registered for topic." + System.lineSeparator() + "topic: " + topicName + "formats: " + keyFormats.stream().map(KeyFormat::getFormat).sorted().collect(Collectors.toList()));
}
// for stream-stream left/outer joins once the above github issue is implemented.
if (valueFormats.size() > 1) {
throw new Exception("Multiple value formats registered for topic." + System.lineSeparator() + "topic: " + topicName + "formats: " + valueFormats.stream().map(ValueFormat::getFormat).sorted().collect(Collectors.toList()));
}
return new TopicInfo(topicName, query.getLogicalSchema(), internalTopic.get().keyFormat(Iterables.getOnlyElement(keyFormats), query), Iterables.getOnlyElement(valueFormats, NONE_VALUE_FORMAT), internalTopic.get().changeLogWindowSize(query));
}
// Source / sink topic:
final Set<TopicInfo> keyTypes = ksqlEngine.getMetaStore().getAllDataSources().values().stream().filter(source -> source.getKafkaTopicName().equals(topicName)).map(source -> new TopicInfo(topicName, source.getSchema(), source.getKsqlTopic().getKeyFormat(), source.getKsqlTopic().getValueFormat(), OptionalLong.empty())).collect(Collectors.toSet());
if (keyTypes.isEmpty()) {
throw new TestFrameworkException("No information found for topic '" + topicName + "'. Available topics: " + cache.asMap().keySet());
}
return Iterables.get(keyTypes, 0);
} catch (final Exception e) {
throw new TestFrameworkException("Failed to determine key type for" + System.lineSeparator() + "topic: " + topicName + System.lineSeparator() + "reason: " + e.getMessage(), e);
}
}
Aggregations