Search in sources :

Example 1 with SourceWarning

use of org.teiid.client.SourceWarning in project teiid by teiid.

the class TestDataTierManager method testPartialResults.

@Test
public void testPartialResults() throws Exception {
    DataTierTupleSource info = helpSetup(1);
    connectorManager.throwExceptionOnExecute = true;
    for (int i = 0; i < 10; i++) {
        try {
            assertNull(info.nextTuple());
            SourceWarning warning = (SourceWarning) context.getAndClearWarnings().get(0);
            assertTrue(warning.isPartialResultsError());
            return;
        } catch (BlockedException e) {
            Thread.sleep(50);
        }
    }
    fail();
}
Also used : SourceWarning(org.teiid.client.SourceWarning) BlockedException(org.teiid.common.buffer.BlockedException) Test(org.junit.Test)

Example 2 with SourceWarning

use of org.teiid.client.SourceWarning in project teiid by teiid.

the class TestExceptionHolder method testSourceWarning.

@Test
public void testSourceWarning() throws Exception {
    // $NON-NLS-1$
    ClassLoader cl = new URLClassLoader(new URL[] { UnitTestUtil.getTestDataFile("test.jar").toURI().toURL() });
    ArrayList<String> args = new ArrayList<String>();
    // $NON-NLS-1$
    args.add("Unknown Exception");
    // $NON-NLS-1$
    Exception obj = (Exception) ReflectionHelper.create("test.UnknownException", args, cl);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(new ExceptionHolder(new SourceWarning("x", "y", obj, true)));
    oos.flush();
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    ExceptionHolder holder = (ExceptionHolder) ois.readObject();
    SourceWarning sw = (SourceWarning) holder.getException();
    assertEquals(sw.getConnectorBindingName(), "y");
    assertEquals(sw.getModelName(), "x");
    assertTrue(sw.isPartialResultsError());
    try {
        ois = new ObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("old-exceptionholder.ser")));
        holder = (ExceptionHolder) ois.readObject();
        assertTrue(holder.getException() instanceof TeiidException);
    } finally {
        ois.close();
    }
}
Also used : SourceWarning(org.teiid.client.SourceWarning) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) SQLException(java.sql.SQLException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) FileInputStream(java.io.FileInputStream) TeiidException(org.teiid.core.TeiidException) ByteArrayInputStream(java.io.ByteArrayInputStream) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 3 with SourceWarning

use of org.teiid.client.SourceWarning in project teiid by teiid.

the class DataTierTupleSource method receiveResults.

void receiveResults(AtomicResultsMessage response, boolean partial) {
    this.arm = response;
    this.scope = response.getScope();
    if (this.scope != null) {
        this.aqr.getCommandContext().setDeterminismLevel(CachingTupleSource.getDeterminismLevel(this.scope));
    }
    explicitClose |= !arm.supportsImplicitClose();
    rowsProcessed += response.getResults().length;
    index = 0;
    if (response.getWarnings() != null) {
        for (Exception warning : response.getWarnings()) {
            SourceWarning sourceFailure = new SourceWarning(this.aqr.getModelName(), aqr.getConnectorName(), warning, partial);
            this.aqr.getCommandContext().addWarning(sourceFailure);
        }
    }
    if (response.getFinalRow() >= 0) {
        done = true;
    }
}
Also used : SourceWarning(org.teiid.client.SourceWarning) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) CancellationException(java.util.concurrent.CancellationException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) BlockedException(org.teiid.common.buffer.BlockedException)

Example 4 with SourceWarning

use of org.teiid.client.SourceWarning in project teiid by teiid.

the class ExceptionHolder method writeExternal.

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    List<String> classNames = new ArrayList<String>();
    Class<?> clazz = exception.getClass();
    while (clazz != null) {
        if (clazz == Throwable.class || clazz == Exception.class) {
            break;
        }
        classNames.add(clazz.getName());
        clazz = clazz.getSuperclass();
    }
    ExternalizeUtil.writeList(out, classNames);
    out.writeObject(exception.getMessage());
    out.writeObject(exception.getStackTrace());
    if (exception instanceof TeiidException) {
        out.writeObject(((TeiidException) exception).getCode());
    } else {
        out.writeObject(null);
    }
    // specify that this cause is nested exception; not top level
    if (this.exception.getCause() != null && this.exception.getCause() != this.exception) {
        out.writeObject(new ExceptionHolder(this.exception.getCause(), true));
    } else {
        out.writeObject(null);
    }
    // only for the top level exception write the serialized block for the object
    if (!nested) {
        out.writeObject(writeAsByteArray(this.exception));
    } else {
        out.writeObject(null);
    }
    // handle SQLException chains
    if (exception instanceof SQLException) {
        if (nested) {
            out.writeInt(0);
        } else {
            SQLException se = (SQLException) exception;
            SQLException next = se.getNextException();
            int count = 0;
            while (next != null) {
                count++;
                next = next.getNextException();
            }
            out.writeInt(count);
            next = se.getNextException();
            while (next != null) {
                out.writeObject(new ExceptionHolder(next, true));
                next = next.getNextException();
            }
        }
    } else if (exception instanceof SourceWarning) {
        SourceWarning sw = (SourceWarning) exception;
        out.writeUTF(sw.getConnectorBindingName());
        out.writeUTF(sw.getModelName());
        out.writeBoolean(sw.isPartialResultsError());
    }
}
Also used : SQLException(java.sql.SQLException) SourceWarning(org.teiid.client.SourceWarning) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException) TeiidException(org.teiid.core.TeiidException)

Example 5 with SourceWarning

use of org.teiid.client.SourceWarning in project teiid by teiid.

the class WarningUtil method createWarning.

/**
 * Used to wrap warnings/exceptions into SQLWarning.
 * The chain of warnings is translated into a chain of SQLWarnings.
 * @param reason String object which is the description of the warning.
 * @param ex Throwable object which needs to be wrapped.
 */
static SQLWarning createWarning(Throwable ex) {
    String sourceName = null;
    String modelName = null;
    if (ex instanceof SourceWarning) {
        SourceWarning exception = (SourceWarning) ex;
        if (exception.isPartialResultsError()) {
            // $NON-NLS-1$
            PartialResultsWarning warning = new PartialResultsWarning(JDBCPlugin.Util.getString("WarningUtil.Failures_occurred"));
            warning.addConnectorFailure(exception.getConnectorBindingName(), TeiidSQLException.create(exception));
            return warning;
        }
        ex = exception.getCause();
        sourceName = exception.getConnectorBindingName();
        modelName = exception.getModelName();
    }
    String code = null;
    if (ex instanceof TeiidException) {
        code = ((TeiidException) ex).getCode();
    }
    return new TeiidSQLWarning(ex.getMessage(), code, ex, sourceName, modelName);
}
Also used : SourceWarning(org.teiid.client.SourceWarning) TeiidException(org.teiid.core.TeiidException)

Aggregations

SourceWarning (org.teiid.client.SourceWarning)6 Test (org.junit.Test)3 BlockedException (org.teiid.common.buffer.BlockedException)3 TeiidException (org.teiid.core.TeiidException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 TeiidComponentException (org.teiid.core.TeiidComponentException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 URLClassLoader (java.net.URLClassLoader)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)1 TranslatorException (org.teiid.translator.TranslatorException)1