Exemplo n.º 1
0
    def test_lookup_alternate(self):
        dtab = Dtab.read("""/zk#    =>      /$/com.twitter.serverset;
                        /zk     =>      /zk#;
                        /s##    =>      /zk/zk.local.twitter.com:2181;
                        /s#     =>      /s##/prod;
                        /s      =>      /s#;
                        /s#     =>      /s##/staging;""")

        one = NameTree.read("/s/crawler")
        two = dtab.lookup(one)
        self.assertEqual(two, NameTree.read("/s#/crawler"))
        alternates = dtab.lookup(two)
        self.assertIsInstance(alternates, NameTree.Alt)
        self.assertEqual(len(alternates), 2)

        self.assertEqual(alternates.trees[0],
                         NameTree.read("/s##/staging/crawler"))
        three0 = dtab.lookup(alternates.trees[0])
        self.assertEqual(
            three0,
            NameTree.read("/zk/zk.local.twitter.com:2181/staging/crawler"))
        four0 = dtab.lookup(three0)
        self.assertEqual(
            four0,
            NameTree.read("/zk#/zk.local.twitter.com:2181/staging/crawler"))
        five0 = dtab.lookup(four0)
        self.assertEqual(
            five0,
            NameTree.read(
                "/$/com.twitter.serverset/zk.local.twitter.com:2181/staging/crawler"
            ),
        )

        self.assertEqual(alternates.trees[1],
                         NameTree.read("/s##/prod/crawler"))
        three1 = dtab.lookup(alternates.trees[1])
        self.assertEqual(
            three1,
            NameTree.read("/zk/zk.local.twitter.com:2181/prod/crawler"))
        four1 = dtab.lookup(three1)
        self.assertEqual(
            four1,
            NameTree.read("/zk#/zk.local.twitter.com:2181/prod/crawler"))
        five1 = dtab.lookup(four1)
        self.assertEqual(
            five1,
            NameTree.read(
                "/$/com.twitter.serverset/zk.local.twitter.com:2181/prod/crawler"
            ),
        )
Exemplo n.º 2
0
    def test_lookup_simple(self):
        dtab = Dtab.read("""/zk#    =>      /$/com.twitter.serverset;
                        /zk     =>      /zk#;
                        /s##    =>      /zk/zk.local.twitter.com:2181;
                        /s#     =>      /s##/prod;
                        /s      =>      /s#;""")

        one = NameTree.read("/s/crawler")
        two = dtab.lookup(one)
        self.assertEqual(two, NameTree.read("/s#/crawler"))
        three = dtab.lookup(two)
        self.assertEqual(three, NameTree.read("/s##/prod/crawler"))
        four = dtab.lookup(three)
        self.assertEqual(
            four, NameTree.read("/zk/zk.local.twitter.com:2181/prod/crawler"))
        five = dtab.lookup(four)
        self.assertEqual(
            five, NameTree.read("/zk#/zk.local.twitter.com:2181/prod/crawler"))
        six = dtab.lookup(five)
        self.assertEqual(
            six,
            NameTree.read(
                "/$/com.twitter.serverset/zk.local.twitter.com:2181/prod/crawler"
            ),
        )