GroupHintParser { public static GroupIndex convertHint2Index(String sql) { String groupIndexHint = extractTDDLGroupHint(sql); if (null != groupIndexHint && !groupIndexHint.equals("")) { String[] hintWithRetry = groupIndexHint.split(","); if (hintWithRetry.length == 1) { int index = GroupHintParser.getIndexFromHintPiece(hintWithRetry[0]); return new GroupIndex(index, false); } else if (hintWithRetry.length == 2) { int index = GroupHintParser.getIndexFromHintPiece(hintWithRetry[0]); boolean retry = GroupHintParser.getFailRetryFromHintPiece(hintWithRetry[1]); return new GroupIndex(index, retry); } else { throw new IllegalArgumentException("the standard group hint is:'groupIndex:12[,failRetry:true]'" + ",current hint is:" + groupIndexHint); } } else { return null; } }  static GroupIndex convertHint2Index(String sql); static String extractTDDLGroupHint(String sql); static String removeTddlGroupHint(String sql); static String buildTddlGroupHint(String groupHint); static void main(String[] args); static Logger log; }
@Test public void testExceptionOnlyRetry() { String sql = "select * from tab"; try { GroupHintParser.convertHint2Index(sql); Assert.fail(); } catch (Exception e) { Assert.assertEquals("the standard group hint is:'groupIndex:12[,failRetry:true]',current index hint is:failRetry:true", e.getMessage()); } }
@Test public void testExceptionErrorHint() { String sql = "select * from tab"; try { GroupHintParser.convertHint2Index(sql); Assert.fail(); } catch (Exception e) { Assert.assertEquals("the standard group hint is:'groupIndex:12[,failRetry:true]',current index hint is:groupIndexx:12", e.getMessage()); } }
@Test public void testSingleIndex() { String sql = "select * from tab"; GroupIndex index = GroupHintParser.convertHint2Index(sql); Assert.assertEquals(index.index, 12); Assert.assertEquals(index.failRetry, false); }
@Test public void testIndexWithRetry() { String sql = "select * from tab"; GroupIndex index = GroupHintParser.convertHint2Index(sql); Assert.assertEquals(index.index, 12); Assert.assertEquals(index.failRetry, true); }
@Test public void testNoIndexHint() { String sql = "select * from tab"; GroupIndex index = GroupHintParser.convertHint2Index(sql); Assert.assertNull(index); }