use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.
the class TestHelper method getConfigurations.
public static AsterixConfiguration getConfigurations(String fileName) throws IOException, JAXBException, AsterixException {
try (InputStream is = TestHelper.class.getClassLoader().getResourceAsStream(fileName)) {
if (is != null) {
JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
return (AsterixConfiguration) unmarshaller.unmarshal(is);
} else {
throw new AsterixException("Could not find configuration file " + fileName);
}
}
}
use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.
the class DmlTest method enlistTest.
@Test
public void enlistTest() throws Exception {
File outdir = new File(PATH_ACTUAL);
if (outdir.exists()) {
AsterixTestHelper.deleteRec(outdir);
}
outdir.mkdirs();
integrationUtil.init(true);
Reader loadReader = new BufferedReader(new InputStreamReader(new FileInputStream(LOAD_FOR_ENLIST_FILE), "UTF-8"));
AsterixJavaClient asterixLoad = new AsterixJavaClient((ICcApplicationContext) integrationUtil.cc.getApplicationContext(), integrationUtil.getHyracksClientConnection(), loadReader, ERR, new AqlCompilationProvider(), new DefaultStatementExecutorFactory(), new StorageComponentProvider());
try {
asterixLoad.compile(true, false, false, false, false, true, false);
} catch (AsterixException e) {
throw new Exception("Compile ERROR for " + LOAD_FOR_ENLIST_FILE + ": " + e.getMessage(), e);
} finally {
loadReader.close();
}
asterixLoad.execute();
integrationUtil.deinit(true);
for (String d : ASTERIX_DATA_DIRS) {
testExecutor.deleteRec(new File(d));
}
outdir.delete();
}
use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.
the class OptimizerTest method test.
@Test
public void test() throws Exception {
try {
String queryFileShort = queryFile.getPath().substring(PATH_QUERIES.length()).replace(SEPARATOR.charAt(0), '/');
if (!only.isEmpty()) {
boolean toRun = TestHelper.isInPrefixList(only, queryFileShort);
if (!toRun) {
LOGGER.info("SKIP TEST: \"" + queryFile.getPath() + "\" \"only.txt\" not empty and not in \"only.txt\".");
}
Assume.assumeTrue(toRun);
}
boolean skipped = TestHelper.isInPrefixList(ignore, queryFileShort);
if (skipped) {
LOGGER.info("SKIP TEST: \"" + queryFile.getPath() + "\" in \"ignore.txt\".");
}
Assume.assumeTrue(!skipped);
LOGGER.info("RUN TEST: \"" + queryFile.getPath() + "\"");
Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(queryFile), "UTF-8"));
// Forces the creation of actualFile.
actualFile.getParentFile().mkdirs();
PrintWriter plan = new PrintWriter(actualFile);
ILangCompilationProvider provider = queryFile.getName().endsWith("aql") ? aqlCompilationProvider : sqlppCompilationProvider;
if (extensionLangCompilationProvider != null) {
provider = extensionLangCompilationProvider;
}
IHyracksClientConnection hcc = integrationUtil.getHyracksClientConnection();
AsterixJavaClient asterix = new AsterixJavaClient((ICcApplicationContext) integrationUtil.cc.getApplicationContext(), hcc, query, plan, provider, statementExecutorFactory, storageComponentProvider);
try {
asterix.compile(true, false, false, true, true, false, false);
} catch (AsterixException e) {
plan.close();
query.close();
throw new Exception("Compile ERROR for " + queryFile + ": " + e.getMessage(), e);
}
plan.close();
query.close();
BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile), "UTF-8"));
BufferedReader readerActual = new BufferedReader(new InputStreamReader(new FileInputStream(actualFile), "UTF-8"));
String lineExpected, lineActual;
int num = 1;
try {
while ((lineExpected = readerExpected.readLine()) != null) {
lineActual = readerActual.readLine();
if (lineActual == null) {
throw new Exception("Result for " + queryFile + " changed at line " + num + ":\n< " + lineExpected + "\n> ");
}
if (!lineExpected.equals(lineActual)) {
throw new Exception("Result for " + queryFile + " changed at line " + num + ":\n< " + lineExpected + "\n> " + lineActual);
}
++num;
}
lineActual = readerActual.readLine();
if (lineActual != null) {
throw new Exception("Result for " + queryFile + " changed at line " + num + ":\n< \n> " + lineActual);
}
LOGGER.info("Test \"" + queryFile.getPath() + "\" PASSED!");
actualFile.delete();
} finally {
readerExpected.close();
readerActual.close();
}
} catch (Exception e) {
if (!(e instanceof AssumptionViolatedException)) {
LOGGER.severe("Test \"" + queryFile.getPath() + "\" FAILED!");
throw new Exception("Test \"" + queryFile.getPath() + "\" FAILED!", e);
} else {
throw e;
}
}
}
use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.
the class ResultExtractor method extract.
public static InputStream extract(InputStream resultStream) throws Exception {
ObjectMapper om = new ObjectMapper();
String resultStr = IOUtils.toString(resultStream, Charset.defaultCharset());
PrettyPrinter singleLine = new SingleLinePrettyPrinter();
ObjectNode result = om.readValue(resultStr, ObjectNode.class);
LOGGER.fine("+++++++\n" + result + "\n+++++++\n");
String type = "";
String status = "";
String results = "";
String field = "";
for (Iterator<String> sIter = result.fieldNames(); sIter.hasNext(); ) {
field = sIter.next();
switch(field) {
case "requestID":
break;
case "clientContextID":
break;
case "signature":
break;
case "status":
status = om.writeValueAsString(result.get(field));
break;
case "type":
type = om.writeValueAsString(result.get(field));
break;
case "metrics":
LOGGER.fine(om.writeValueAsString(result.get(field)));
break;
case "errors":
JsonNode errors = result.get(field).get(0).get("msg");
throw new AsterixException(errors.asText());
case "results":
if (result.get(field).size() <= 1) {
if (result.get(field).size() == 0) {
results = "";
} else if (result.get(field).isArray()) {
if (result.get(field).get(0).isTextual()) {
results = result.get(field).get(0).asText();
} else {
ObjectMapper omm = new ObjectMapper();
omm.setDefaultPrettyPrinter(singleLine);
omm.enable(SerializationFeature.INDENT_OUTPUT);
results = omm.writer(singleLine).writeValueAsString(result.get(field));
}
} else {
results = om.writeValueAsString(result.get(field));
}
} else {
StringBuilder sb = new StringBuilder();
JsonNode[] fields = Iterators.toArray(result.get(field).elements(), JsonNode.class);
if (fields.length > 1) {
for (JsonNode f : fields) {
if (f.isObject()) {
sb.append(om.writeValueAsString(f));
} else {
sb.append(f.asText());
}
}
}
results = sb.toString();
}
break;
default:
throw new AsterixException("Unanticipated field \"" + field + "\"");
}
}
return IOUtils.toInputStream(results);
}
use of org.apache.asterix.common.exceptions.AsterixException in project asterixdb by apache.
the class ResultExtractor method extractHandle.
public static String extractHandle(InputStream resultStream) throws Exception {
final Charset utf8 = Charset.forName("UTF-8");
ObjectMapper om = new ObjectMapper();
String result = IOUtils.toString(resultStream, utf8);
ObjectNode resultJson = om.readValue(result, ObjectNode.class);
final JsonNode handle = resultJson.get("handle");
if (handle != null) {
return handle.asText();
} else {
JsonNode errors = resultJson.get("errors");
if (errors != null) {
JsonNode msg = errors.get(0).get("msg");
throw new AsterixException(msg.asText());
}
}
return null;
}
Aggregations