Skip to content

Commit

Permalink
TEIID-3989 adding built-in logic for sourcewarnings as well
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Feb 24, 2016
1 parent c649c4a commit a91ad2b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
17 changes: 17 additions & 0 deletions client/src/main/java/org/teiid/client/util/ExceptionHolder.java
Expand Up @@ -28,6 +28,7 @@
import java.util.Arrays;
import java.util.List;

import org.teiid.client.SourceWarning;
import org.teiid.core.CorePlugin;
import org.teiid.core.TeiidException;
import org.teiid.core.TeiidRuntimeException;
Expand Down Expand Up @@ -85,6 +86,17 @@ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundExcept
} catch (OptionalDataException e) {

}
} else if (!classNames.isEmpty() && classNames.get(0).equals(SourceWarning.class.getName())) {
try {
String connectorBindingName = in.readUTF();
String modelName = in.readUTF();
boolean partial = in.readBoolean();
this.exception = new SourceWarning(modelName, connectorBindingName, this.exception.getCause(), partial);
} catch (EOFException e) {
//for backwards compatibility
} catch (OptionalDataException e) {
//for backwards compatibility
}
}
}
}
Expand Down Expand Up @@ -143,6 +155,11 @@ public void writeExternal(ObjectOutput out) throws IOException {
next = next.getNextException();
}
}
} else if (exception instanceof SourceWarning) {
SourceWarning sw = (SourceWarning)exception;
out.writeUTF(sw.getConnectorBindingName());
out.writeUTF(sw.getModelName());
out.writeBoolean(sw.isPartialResultsError());
}
}

Expand Down
Expand Up @@ -26,6 +26,7 @@

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
Expand All @@ -37,6 +38,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.Test;
import org.teiid.client.SourceWarning;
import org.teiid.core.TeiidException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidRuntimeException;
Expand Down Expand Up @@ -202,4 +204,32 @@ private static class NotSerializable {
Throwable e = holder.getException();
assertTrue(e instanceof TeiidException);
}

@Test public void testSourceWarning() throws Exception {
ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$
ArrayList<String> args = new ArrayList<String>();
args.add("Unknown Exception"); //$NON-NLS-1$
Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", args, cl); //$NON-NLS-1$

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();
}

}
}
Binary file not shown.

0 comments on commit a91ad2b

Please sign in to comment.