ShardingCTLHintBackendHandler implements TextProtocolBackendHandler { @SuppressWarnings("unchecked") @Override public BackendResponse execute() { if (!ProxyContext.getInstance().getSchemaContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.PROXY_HINT_ENABLED)) { throw new UnsupportedOperationException(String.format("%s should be true, please check your config", ConfigurationPropertyKey.PROXY_HINT_ENABLED.getKey())); } Optional<ShardingCTLHintStatement> shardingTCLStatement = new ShardingCTLHintParser(sql).doParse(); if (!shardingTCLStatement.isPresent()) { throw new InvalidShardingCTLFormatException(sql); } HintCommand hintCommand = shardingTCLStatement.get().getHintCommand(); hintCommandExecutor = HintCommandExecutorFactory.newInstance(hintCommand, backendConnection, sql); return hintCommandExecutor.execute(hintCommand); }  @SuppressWarnings("unchecked") @Override BackendResponse execute(); @Override boolean next(); @Override QueryData getQueryData();  }
@Test(expected = InvalidShardingCTLFormatException.class) public void assertInvalidShardingCTLFormat() { clearThreadLocal(); String sql = "sctl:hint1 xx=yy"; new ShardingCTLHintBackendHandler(sql, backendConnection).execute(); }
@Test public void assertSetPrimaryOnly() { clearThreadLocal(); String sql = "sctl:hint set primary_only=true "; ShardingCTLHintBackendHandler hintBackendHandler = new ShardingCTLHintBackendHandler(sql, backendConnection); assertThat(hintBackendHandler.execute(), instanceOf(UpdateResponse.class)); assertTrue(HintManager.isPrimaryRouteOnly()); }
@Test public void assertClear() { clearThreadLocal(); String sql = "sctl:hint clear "; ShardingCTLHintBackendHandler hintBackendHandler = new ShardingCTLHintBackendHandler(sql, backendConnection); assertThat(hintBackendHandler.execute(), instanceOf(UpdateResponse.class)); assertThat(HintManager.getInstance(), instanceOf(HintManager.class)); HintManager.clear(); }
@Test(expected = UnsupportedShardingCTLTypeException.class) public void assertUnsupportedShardingCTLType() { clearThreadLocal(); String sql = "sctl:hint xx=yy"; new ShardingCTLHintBackendHandler(sql, backendConnection).execute(); }