Skip to content

Commit a2b344f

Browse files
authored
Merge pull request #254 from marklogic/feature/error-fix
Capturing an undesirable error condition from Spark
2 parents b194f06 + 8ebe32d commit a2b344f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/java/com/marklogic/spark/writer/WriteRowsTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ void twoPartitions() {
6565
verifyTwoHundredDocsWereWritten();
6666
}
6767

68+
@Test
69+
void insufficientPrivilegeForOtherDatabase() {
70+
DataFrameWriter writer = newWriter(2)
71+
.option(Options.WRITE_TOTAL_THREAD_COUNT, 16)
72+
.option(Options.WRITE_BATCH_SIZE, 10)
73+
.option(Options.CLIENT_URI, "spark-test-user:spark@localhost:8016/Documents");
74+
75+
SparkException ex = assertThrows(SparkException.class, () -> writer.save());
76+
assertNull(ex.getCause(), "Surprisingly, in this scenario where the exception is thrown during the " +
77+
"construction of WriteBatcherDataWriter, Spark does not populate the 'cause' of the exception but rather " +
78+
"shoves the entire stacktrace of the exception into the exception message. This is not a good UX for " +
79+
"connector or Flux users, as it puts an ugly stacktrace right into their face. I have not figured out " +
80+
"how to avoid this yet, so this test is capturing this behavior in the hopes that an upgraded version of " +
81+
"Spark will properly set the cause instead.");
82+
assertTrue(ex.getMessage().contains("at com.marklogic.client.impl.OkHttpServices"), "This is confirming that " +
83+
"the exception message contains the stacktrace of the MarkLogic exception - which we don't want. Hoping " +
84+
"this assertion breaks during a future upgrade of Spark and we have a proper exception message " +
85+
"instead. Actual message: " + ex.getMessage());
86+
}
87+
6888
@Test
6989
void temporalTest() {
7090
newWriterWithDefaultConfig("temporal-data.csv", 1)

0 commit comments

Comments
 (0)