|
88 | 88 | import com.mysql.cj.xdevapi.ClientFactory;
|
89 | 89 | import com.mysql.cj.xdevapi.ClientImpl;
|
90 | 90 | import com.mysql.cj.xdevapi.ClientImpl.PooledXProtocol;
|
| 91 | +import com.mysql.cj.xdevapi.Collection; |
| 92 | +import com.mysql.cj.xdevapi.DbDoc; |
| 93 | +import com.mysql.cj.xdevapi.DocResult; |
91 | 94 | import com.mysql.cj.xdevapi.FindStatement;
|
| 95 | +import com.mysql.cj.xdevapi.JsonNumber; |
| 96 | +import com.mysql.cj.xdevapi.JsonString; |
92 | 97 | import com.mysql.cj.xdevapi.Row;
|
93 | 98 | import com.mysql.cj.xdevapi.RowResult;
|
94 | 99 | import com.mysql.cj.xdevapi.Schema;
|
@@ -2566,4 +2571,90 @@ public void testExecAsyncNegative() throws Exception {
|
2566 | 2571 | sqlUpdate("drop table if exists testExecAsyncNegative");
|
2567 | 2572 | }
|
2568 | 2573 | }
|
| 2574 | + |
| 2575 | + /** |
| 2576 | + * Test fix for Bug#97269 (30438500), POSSIBLE BUG IN COM.MYSQL.CJ.XDEVAPI.STREAMINGDOCRESULTBUILDER. |
| 2577 | + * |
| 2578 | + * @throws Exception |
| 2579 | + */ |
| 2580 | + @Test |
| 2581 | + public void testBug97269() throws Exception { |
| 2582 | + assumeTrue(this.isSetForXTests); |
| 2583 | + |
| 2584 | + Session sess = null; |
| 2585 | + try { |
| 2586 | + String message1 = "W1"; |
| 2587 | + String message2 = "W2"; |
| 2588 | + |
| 2589 | + // create notice message buffers |
| 2590 | + Frame.Builder notice1 = Frame.newBuilder().setScope(Frame.Scope.LOCAL).setType(Frame.Type.WARNING_VALUE) |
| 2591 | + .setPayload(com.mysql.cj.x.protobuf.MysqlxNotice.Warning.newBuilder().setCode(MysqlErrorNumbers.ER_BAD_DB_ERROR).setMsg(message1).build() |
| 2592 | + .toByteString()); |
| 2593 | + Frame.Builder notice2 = Frame.newBuilder().setScope(Frame.Scope.GLOBAL).setType(Frame.Type.WARNING_VALUE) |
| 2594 | + .setPayload(com.mysql.cj.x.protobuf.MysqlxNotice.Warning.newBuilder().setCode(MysqlErrorNumbers.ER_BAD_DB_ERROR).setMsg(message2).build() |
| 2595 | + .toByteString()); |
| 2596 | + |
| 2597 | + byte[] notice1Bytes = makeNoticeBytes(notice1.build()); |
| 2598 | + byte[] notice2Bytes = makeNoticeBytes(notice2.build()); |
| 2599 | + int size = notice1Bytes.length + notice2Bytes.length; |
| 2600 | + byte[] noticesBytes = new byte[size]; |
| 2601 | + System.arraycopy(notice1Bytes, 0, noticesBytes, 0, notice1Bytes.length); |
| 2602 | + System.arraycopy(notice2Bytes, 0, noticesBytes, notice1Bytes.length, notice2Bytes.length); |
| 2603 | + |
| 2604 | + InjectedSocketFactory.flushAllStaticData(); |
| 2605 | + |
| 2606 | + String url = this.baseUrl + (this.baseUrl.contains("?") ? "" : "?") |
| 2607 | + + makeParam(PropertyKey.socketFactory, InjectedSocketFactory.class.getName(), !this.baseUrl.contains("?") || this.baseUrl.endsWith("?")) |
| 2608 | + + makeParam(PropertyKey.xdevapiSslMode, XdevapiSslMode.DISABLED.toString()) |
| 2609 | + + makeParam(PropertyKey.xdevapiCompression, Compression.DISABLED.toString()) |
| 2610 | + // to allow injection between result rows |
| 2611 | + + makeParam(PropertyKey.useReadAheadInput, "false"); |
| 2612 | + |
| 2613 | + sess = this.fact.getSession(url); |
| 2614 | + SocketFactory sf = ((SessionImpl) sess).getSession().getProtocol().getSocketConnection().getSocketFactory(); |
| 2615 | + assertTrue(InjectedSocketFactory.class.isAssignableFrom(sf.getClass())); |
| 2616 | + |
| 2617 | + Collection collection = sess.getDefaultSchema().createCollection("testBug97269"); |
| 2618 | + collection.add("{\"_id\":\"the_id\",\"g\":1}").execute(); |
| 2619 | + |
| 2620 | + // StreamingDocResultBuilder |
| 2621 | + InjectedSocketFactory.injectedBuffer = noticesBytes; |
| 2622 | + DocResult docs = collection.find().fields("$._id as _id, $.g as g, 1 + 1 as q").execute(); |
| 2623 | + DbDoc doc = docs.next(); |
| 2624 | + assertEquals("the_id", ((JsonString) doc.get("_id")).getString()); |
| 2625 | + assertEquals(new Integer(1), ((JsonNumber) doc.get("g")).getInteger()); |
| 2626 | + assertEquals(new Integer(2), ((JsonNumber) doc.get("q")).getInteger()); |
| 2627 | + |
| 2628 | + int cnt = 0; |
| 2629 | + for (Iterator<Warning> warn = docs.getWarnings(); warn.hasNext();) { |
| 2630 | + Warning w = warn.next(); |
| 2631 | + if (w.getMessage().equals(message1) || w.getMessage().equals(message2)) { |
| 2632 | + cnt++; |
| 2633 | + } |
| 2634 | + } |
| 2635 | + assertEquals(2, cnt); |
| 2636 | + |
| 2637 | + InjectedSocketFactory.flushAllStaticData(); |
| 2638 | + InjectedSocketFactory.injectedBuffer = noticesBytes; |
| 2639 | + |
| 2640 | + SqlResult rs1 = sess.sql("select 1").execute(); |
| 2641 | + assertEquals(1, rs1.fetchOne().getInt(0)); |
| 2642 | + cnt = 0; |
| 2643 | + for (Iterator<Warning> warn = rs1.getWarnings(); warn.hasNext();) { |
| 2644 | + Warning w = warn.next(); |
| 2645 | + if (w.getMessage().equals(message1) || w.getMessage().equals(message2)) { |
| 2646 | + cnt++; |
| 2647 | + } |
| 2648 | + } |
| 2649 | + assertEquals(2, cnt); |
| 2650 | + |
| 2651 | + } finally { |
| 2652 | + InjectedSocketFactory.flushAllStaticData(); |
| 2653 | + dropCollection("testBug97269"); |
| 2654 | + if (sess != null) { |
| 2655 | + sess.close(); |
| 2656 | + } |
| 2657 | + } |
| 2658 | + |
| 2659 | + } |
2569 | 2660 | }
|
0 commit comments