Package com.alibaba.cobar.client.router.support

Examples of com.alibaba.cobar.client.router.support.IBatisRoutingFact


                                                                      final Object parameterObject) {
        SortedMap<String, DataSource> resultMap = new TreeMap<String, DataSource>();

        if (getRouter() != null && getCobarDataSourceService() != null) {
            List<String> dsSet = getRouter().doRoute(
                    new IBatisRoutingFact(statementName, parameterObject)).getResourceIdentities();
            if (CollectionUtils.isNotEmpty(dsSet)) {
                Collections.sort(dsSet);
                for (String dsName : dsSet) {
                    resultMap.put(dsName, getCobarDataSourceService().getDataSources().get(dsName));
                }
View Full Code Here


            // pass
        }
    }

    public void testSqlActionRuleOnTypePatternNormally() {
        IBatisRoutingFact fact = new IBatisRoutingFact(SQL_MAP_ACTION_ID, null);
        assertTrue(rule.isDefinedAt(fact));
       
        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.del", null);
        assertFalse(rule.isDefinedAt(fact));
       
        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet", null);
        assertFalse(rule.isDefinedAt(fact));
       
        fact = new IBatisRoutingFact(null, null);
        assertFalse(rule.isDefinedAt(fact));
    }
View Full Code Here

    public void testRuleTypePatternMatchingNormally() {
        Tweet t = new Tweet();
        t.setId(15000L);
        t.setTweet("anything");
        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", t);
        assertTrue(rule.isDefinedAt(fact));

        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.update", t);
        assertTrue(rule.isDefinedAt(fact));

        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Follower.update", t);
        assertFalse(rule.isDefinedAt(fact));
    }
View Full Code Here

    public void testRuleShardingPatternMatchingNormally() {
        Tweet t = new Tweet();
        t.setId(15000L);
        t.setTweet("anything");
        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.update", t);
        assertTrue(rule.isDefinedAt(fact));

        t.setId(20000001L);
        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.update", t);
        assertFalse(rule.isDefinedAt(fact));

        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.update", null);
        assertFalse(rule.isDefinedAt(fact));

        Map<String, Long> ctx = new HashMap<String, Long>();
        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.update", ctx);
        assertFalse(rule.isDefinedAt(fact));

        ctx.put("id", 18000L);
        assertTrue(rule.isDefinedAt(fact));
View Full Code Here

        r.setFunctionMap(functions);

        Tweet t = new Tweet();
        t.setId(3L);
        t.setTweet("anything");
        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", t);
        assertTrue(r.isDefinedAt(fact));
    }
View Full Code Here

    public void testRuleExpressionEvaluationWithSimpleTypeRoutingFact()
    {
        IBatisNamespaceShardingRule r = new IBatisNamespaceShardingRule(DEFAULT_TYPE_PATTEN,
                "shard2", "$ROOT.startsWith(\"A\")");
       
        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", "Arron");
        assertTrue(r.isDefinedAt(fact));
       
        r = new IBatisNamespaceShardingRule(DEFAULT_TYPE_PATTEN,
                "shard2", "startsWith(\"A\")");
        assertTrue(r.isDefinedAt(fact));
       
        fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", "Donald");
        assertFalse(r.isDefinedAt(fact));
    }
View Full Code Here

                "p1, p2");
        List<String> shardIds = rule.action();
        assertNotNull(shardIds);
        assertEquals(2, shardIds.size());

        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.update", null);
        assertTrue(rule.isDefinedAt(fact));
        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.delete", null);
        assertTrue(rule.isDefinedAt(fact));
        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Twet.delete", null);
        assertFalse(rule.isDefinedAt(fact));
    }
View Full Code Here

        shards = null;
        shards = rule.action();
        assertTrue(CollectionUtils.isNotEmpty(shards));
        assertEquals(2, shards.size());

        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.update", null);
        assertTrue(rule.isDefinedAt(fact));
        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.delete", null);
        assertTrue(rule.isDefinedAt(fact));
        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Twet.delete", null);
        assertFalse(rule.isDefinedAt(fact));
    }
View Full Code Here

    public void testSqlActionShardingRulePatternMatchingNormally() {
        Tweet t = new Tweet();
        t.setId(15000L);
        t.setTweet("anything");

        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", t);
        assertTrue(rule.isDefinedAt(fact));
        List<String> shards = rule.action();
        assertTrue(CollectionUtils.isNotEmpty(shards));
        assertEquals(2, shards.size());
        for (String shard : shards) {
            assertTrue(ArrayUtils.contains(DEFAULT_SHARDS, shard));
        }

        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.update", t);
        assertFalse(rule.isDefinedAt(fact));

        t.setId(20000L);
        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.create", t);
        assertFalse(rule.isDefinedAt(fact));

        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.create", null);
        assertFalse(rule.isDefinedAt(fact));

        fact = new IBatisRoutingFact("com.alibaba.cobar.client.entity.Tweet.create", new Object());
        assertFalse(rule.isDefinedAt(fact));
    }
View Full Code Here

        r.setFunctionMap(functions);
       
        Tweet t = new Tweet();
        t.setId(21L);
        t.setTweet("anything");
        IBatisRoutingFact fact = new IBatisRoutingFact(
                "com.alibaba.cobar.client.entity.Tweet.create", t);
        assertTrue(r.isDefinedAt(fact));
    }
View Full Code Here

TOP

Related Classes of com.alibaba.cobar.client.router.support.IBatisRoutingFact

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.