示例#1
0
  public static int Main(string[] args)
    {
    string directory = args[0];
    Tag t = new Tag(0x8,0x80);

    Directory d = new Directory();
    uint nfiles = d.Load( directory );
    if(nfiles == 0) return 1;
    //System.Console.WriteLine( "Files:\n" + d.toString() );

    // Use a StrictScanner, need to use a reference to pass the C++ pointer to
    // MyWatcher implementation
    SmartPtrStrictScan sscan = StrictScanner.New();
    StrictScanner s = sscan.__ref__();
    MyWatcher watcher = new MyWatcher(s);

    s.AddTag( t );
    bool b = s.Scan( d.GetFilenames() );
    if(!b) return 1;

    for(int i = 0; i < (int)nfiles; ++i)
      {
      if( !s.IsKey( d.GetFilenames()[i] ) )
        {
        System.Console.WriteLine( "File is not DICOM or could not be read: " + d.GetFilenames()[i] );
        }
      }

    System.Console.WriteLine( "Scan:\n" + s.toString() );

    System.Console.WriteLine( "success" );
    return 0;
    }
示例#2
0
        public async Task testWatcherCorrectness()
        {
            ZooKeeper zk      = null;
            MyWatcher watcher = new MyWatcher();

            zk = await createClient(watcher);

            string[] names = new string[10];
            for (int i = 0; i < names.Length; i++)
            {
                string name = await zk.createAsync("/tc-", "initialvalue".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);

                names[i] = name;

                Stat stat = (await zk.getDataAsync(name, watcher)).Stat;
                await zk.setDataAsync(name, "new".UTF8getBytes(), stat.getVersion());

                stat = await zk.existsAsync(name, watcher);

                await zk.deleteAsync(name, stat.getVersion());
            }

            for (int i = 0; i < names.Length; i++)
            {
                string       name   = names[i];
                WatchedEvent @event = watcher.events.poll(10 * 1000);
                Assert.assertEquals(name, @event.getPath());
                Assert.assertEquals(Watcher.Event.EventType.NodeDataChanged, @event.get_Type());
                Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());
                @event = watcher.events.poll(10 * 1000);
                Assert.assertEquals(name, @event.getPath());
                Assert.assertEquals(Watcher.Event.EventType.NodeDeleted, @event.get_Type());
                Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());
            }
        }
示例#3
0
    public static int Main(string[] args)
    {
        gdcm.Global global = gdcm.Global.GetInstance();
        if (!global.LoadResourcesFiles())
        {
            System.Console.WriteLine("Could not LoadResourcesFiles");
            return(1);
        }

        string file1  = args[0];
        string file2  = args[1];
        Reader reader = new Reader();

        reader.SetFileName(file1);
        bool ret = reader.Read();

        if (!ret)
        {
            return(1);
        }

        string certpath = gdcm.Filename.Join(gdcm.Testing.GetSourceDirectory(), "/Testing/Source/Data/certificate.pem");

        gdcm.CryptoFactory fact             = gdcm.CryptoFactory.GetFactoryInstance();
        gdcm.CryptographicMessageSyntax cms = fact.CreateCMSProvider();
        if (!cms.ParseCertificateFile(certpath))
        {
            return(1);
        }

        //Anonymizer ano = new Anonymizer();
        SmartPtrAno sano = Anonymizer.New();
        Anonymizer  ano  = sano.__ref__();

        //SimpleSubjectWatcher watcher = new SimpleSubjectWatcher(ano, "Anonymizer");
        MyWatcher watcher = new MyWatcher(ano);

        ano.SetFile(reader.GetFile());
        ano.SetCryptographicMessageSyntax(cms);
        if (!ano.BasicApplicationLevelConfidentialityProfile())
        {
            return(1);
        }

        Writer writer = new Writer();

        writer.SetFileName(file2);
        writer.SetFile(ano.GetFile());
        ret = writer.Write();
        if (!ret)
        {
            return(1);
        }

        return(0);
    }
示例#4
0
    public static int Main(string[] args)
    {
        gdcm.Global global = gdcm.Global.GetInstance();
        if( !global.LoadResourcesFiles() )
          {
          System.Console.WriteLine( "Could not LoadResourcesFiles" );
          return 1;
          }

        string file1 = args[0];
        string file2 = args[1];
        Reader reader = new Reader();
        reader.SetFileName( file1 );
        bool ret = reader.Read();
        if( !ret )
          {
          return 1;
          }

        string certpath = gdcm.Filename.Join(gdcm.Testing.GetSourceDirectory(), "/Testing/Source/Data/certificate.pem" );
        gdcm.CryptographicMessageSyntax cms = new gdcm.CryptographicMessageSyntax();
        if( !cms.ParseCertificateFile( certpath ) )
          {
          return 1;
          }

        //Anonymizer ano = new Anonymizer();
        SmartPtrAno sano = Anonymizer.New();
        Anonymizer ano = sano.__ref__();

        //SimpleSubjectWatcher watcher = new SimpleSubjectWatcher(ano, "Anonymizer");
        MyWatcher watcher = new MyWatcher(ano);

        ano.SetFile( reader.GetFile() );
        ano.SetCryptographicMessageSyntax( cms );
        if( !ano.BasicApplicationLevelConfidentialityProfile() )
          {
          return 1;
          }

        Writer writer = new Writer();
        writer.SetFileName( file2 );
        writer.SetFile( ano.GetFile() );
        ret = writer.Write();
        if( !ret )
          {
          return 1;
          }

        return 0;
    }
示例#5
0
        public void testWatcherCorrectness()
        {
            ZooKeeper zk = null;

            try
            {
                MyWatcher watcher = new MyWatcher();
                zk = createClient(watcher);

                string[] names = new string[10];
                for (int i = 0; i < names.Length; i++)
                {
                    string name = zk.create("/tc-", "initialvalue".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
                    names[i] = name;

                    Stat stat = new Stat();
                    zk.getData(name, watcher, stat);
                    zk.setData(name, "new".getBytes(), stat.getVersion());
                    stat = zk.exists(name, watcher);
                    zk.delete(name, stat.getVersion());
                }

                for (int i = 0; i < names.Length; i++)
                {
                    string       name   = names[i];
                    WatchedEvent @event = watcher.events.poll(10 * 1000);
                    Assert.assertEquals(name, @event.getPath());
                    Assert.assertEquals(Watcher.Event.EventType.NodeDataChanged, @event.get_Type());
                    Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());
                    @event = watcher.events.poll(10 * 1000);
                    Assert.assertEquals(name, @event.getPath());
                    Assert.assertEquals(Watcher.Event.EventType.NodeDeleted, @event.get_Type());
                    Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());
                }
            }
            finally
            {
                if (zk != null)
                {
                    zk.close();
                }
            }
        }
示例#6
0
        public void testChrootedWatchReestablishment()
        {
            string chroot = "/" + Guid.NewGuid() + "watchtest";

            using (ZooKeeper zk1 = CreateClient())
            {
                Assert.AreEqual(chroot, zk1.Create(chroot, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent));
            }

            ZooKeeper zk      = CreateClient(chroot);
            MyWatcher watcher = new MyWatcher();

            string name = "/watchtest";

            zk.GetChildren("/", watcher);
            zk.Create(name, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Ephemeral);

            WatchedEvent @event;

            Assert.IsTrue(watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3d)));
            Assert.AreEqual("/", @event.Path);
            Assert.AreEqual(EventType.NodeChildrenChanged, @event.Type);
            Assert.AreEqual(KeeperState.SyncConnected, @event.State);

            zk.GetChildren("/", watcher);

            ClientConnection cnxn = (ClientConnection)zk.GetType().GetField("cnxn", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(zk);
            ClientConnectionRequestProducer producer = (ClientConnectionRequestProducer)cnxn.GetType().GetField("producer", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(cnxn);
            TcpClient client = (TcpClient)producer.GetType().GetField("client", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(producer);

            client.Close();
            Thread.Sleep(100);

            zk.Delete(name, -1);

            Assert.IsTrue(watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3d)));
            Assert.AreEqual("/", @event.Path);
            Assert.AreEqual(EventType.NodeChildrenChanged, @event.Type);
            Assert.AreEqual(KeeperState.SyncConnected, @event.State);

            Assert.AreEqual(0, watcher.events.Count);
        }
示例#7
0
    public static int Main(string[] args)
    {
        string directory = args[0];
        Tag    t         = new Tag(0x8, 0x80);

        Directory d      = new Directory();
        uint      nfiles = d.Load(directory);

        if (nfiles == 0)
        {
            return(1);
        }
        //System.Console.WriteLine( "Files:\n" + d.toString() );

        // Use a StrictScanner, need to use a reference to pass the C++ pointer to
        // MyWatcher implementation
        SmartPtrStrictScan sscan   = StrictScanner.New();
        StrictScanner      s       = sscan.__ref__();
        MyWatcher          watcher = new MyWatcher(s);

        s.AddTag(t);
        bool b = s.Scan(d.GetFilenames());

        if (!b)
        {
            return(1);
        }

        for (int i = 0; i < (int)nfiles; ++i)
        {
            if (!s.IsKey(d.GetFilenames()[i]))
            {
                System.Console.WriteLine("File is not DICOM or could not be read: " + d.GetFilenames()[i]);
            }
        }

        System.Console.WriteLine("Scan:\n" + s.toString());

        System.Console.WriteLine("success");
        return(0);
    }
示例#8
0
        static void Main(string[] args)
        {
            string path   = "D:/c#";
            string filter = "*.flg";


            // SqlConnection conn = DBUtils.GetDBConnection(DBSQLServerUtils.SERVER);
            try
            {
                Console.WriteLine("Подключение настроено на : " + DBSQLServerUtils.SERVER);
                MyWatcher watcher = new MyWatcher(path, filter);
                watcher.Run();
            }
            catch (Exception e)
            {
                Shipul.FileOperations.saveException(e);
            }


            Console.ReadKey();
        }
示例#9
0
        private async Task performClientTest(bool withWatcherObj)
        {
            ZooKeeper zk      = null;
            MyWatcher watcher = new MyWatcher();

            zk = await createClient(watcher);

            LOG.info("Before create /benwashere");
            await zk.createAsync("/benwashere", "".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            LOG.info("After create /benwashere");
            try {
                await zk.setDataAsync("/benwashere", "hi".UTF8getBytes(), 57);

                Assert.fail("Should have gotten BadVersion exception");
            }
            catch (KeeperException.BadVersionException) {
                // expected that
            }
            catch (KeeperException) {
                Assert.fail("Should have gotten BadVersion exception");
            }
            LOG.info("Before delete /benwashere");
            await zk.deleteAsync("/benwashere", 0);

            LOG.info("After delete /benwashere");
            //LOG.info("Closed client: " + zk.describeCNXN());
            await Task.Delay(2000);

            zk = await createClient(watcher);

            //LOG.info("Created a new client: " + zk.describeCNXN());
            LOG.info("Before delete /");

            try {
                await zk.deleteAsync("/", -1);

                Assert.fail("deleted root!");
            }
            catch (KeeperException.BadArgumentsException) {
                // good, expected that
            }

            // Test basic create, ls, and getData
            await zk.createAsync("/pat", "Pat was here".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            LOG.info("Before create /ben");
            await zk.createAsync("/pat/ben", "Ben was here".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            LOG.info("Before getChildren /pat");
            List <string> children = (await zk.getChildrenAsync("/pat", false)).Children;

            Assert.assertEquals(1, children.Count);
            Assert.assertEquals("ben", children[0]);
            IList <string> children2 = (await zk.getChildrenAsync("/pat", false)).Children;

            Assert.assertEquals(children, children2);
            Assert.assertEquals("Ben was here", (await zk.getDataAsync("/pat/ben", false)).Data.UTF8bytesToString());
            // Test stat and watch of non existent node

            try {
                if (withWatcherObj)
                {
                    Assert.assertEquals(null, await zk.existsAsync("/frog", watcher));
                }
                else
                {
                    Assert.assertEquals(null, await zk.existsAsync("/frog", true));
                }
                LOG.info("Comment: asseting passed for frog setting /");
            }
            catch (KeeperException.NoNodeException) {
                // OK, expected that
            }
            await zk.createAsync("/frog", "hi".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            // the first poll is just a session delivery
            LOG.info("Comment: checking for events length " + watcher.events.size());
            WatchedEvent @event = watcher.events.poll(10 * 1000);

            Assert.assertEquals("/frog", @event.getPath());
            Assert.assertEquals(Watcher.Event.EventType.NodeCreated, @event.get_Type());
            Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());
            // Test child watch and create with sequence
            await zk.getChildrenAsync("/pat/ben", true);

            for (int i = 0; i < 10; i++)
            {
                await zk.createAsync("/pat/ben/" + i + "-", Convert.ToString(i).UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                                     CreateMode.PERSISTENT_SEQUENTIAL);
            }
            children = (await zk.getChildrenAsync("/pat/ben", false)).Children;
            children.Sort();
            Assert.assertEquals(10, children.Count);
            for (int i = 0; i < 10; i++)
            {
                string name = children[i];
                Assert.assertTrue("starts with -", name.StartsWith(i + "-", StringComparison.Ordinal));
                DataResult dataResult;
                if (withWatcherObj)
                {
                    dataResult = await zk.getDataAsync("/pat/ben/" + name, watcher);
                }
                else
                {
                    dataResult = await zk.getDataAsync("/pat/ben/" + name, true);
                }
                Assert.assertEquals(i, int.Parse(dataResult.Data.UTF8bytesToString()));
                await zk.setDataAsync("/pat/ben/" + name, "new".UTF8getBytes(), dataResult.Stat.getVersion());

                Stat stat;
                if (withWatcherObj)
                {
                    stat = await zk.existsAsync("/pat/ben/" + name, watcher);
                }
                else
                {
                    stat = await zk.existsAsync("/pat/ben/" + name, true);
                }
                await zk.deleteAsync("/pat/ben/" + name, stat.getVersion());
            }
            @event = watcher.events.poll(10 * 1000);
            Assert.assertEquals("/pat/ben", @event.getPath());
            Assert.assertEquals(Watcher.Event.EventType.NodeChildrenChanged, @event.get_Type());
            Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());
            for (int i = 0; i < 10; i++)
            {
                @event = watcher.events.poll(10 * 1000);


                string name = children[i];
                Assert.assertEquals("/pat/ben/" + name, @event.getPath());
                Assert.assertEquals(Watcher.Event.EventType.NodeDataChanged, @event.get_Type());
                Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());
                @event = watcher.events.poll(10 * 1000);
                Assert.assertEquals("/pat/ben/" + name, @event.getPath());
                Assert.assertEquals(Watcher.Event.EventType.NodeDeleted, @event.get_Type());
                Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());
            }
            await zk.createAsync("/good\u0040path", "".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            await zk.createAsync("/duplicate", "".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            try {
                await zk.createAsync("/duplicate", "".UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

                Assert.fail("duplicate create allowed");
            }
            catch (KeeperException.NodeExistsException) {
                // OK, expected that
            }
        }
示例#10
0
        public async Task testMutipleWatcherObjs()
        {
            ZooKeeper zk = await createClient();

            MyWatcher[] watchers  = new MyWatcher[100];
            MyWatcher[] watchers2 = new MyWatcher[watchers.Length];
            for (int i = 0; i < watchers.Length; i++)
            {
                watchers[i]  = new MyWatcher();
                watchers2[i] = new MyWatcher();
                await zk.createAsync("/foo-" + i, ("foodata" + i).UTF8getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                                     CreateMode.PERSISTENT);
            }

            //
            // test get/exists with single set of watchers
            //   get all, then exists all
            //
            for (int i = 0; i < watchers.Length; i++)
            {
                Assert.assertNotNull((await zk.getDataAsync("/foo-" + i, watchers[i])).Data);
            }
            for (int i = 0; i < watchers.Length; i++)
            {
                Assert.assertNotNull(await zk.existsAsync("/foo-" + i, watchers[i]));
            }
            // trigger the watches
            for (int i = 0; i < watchers.Length; i++)
            {
                await zk.setDataAsync("/foo-" + i, ("foodata2-" + i).UTF8getBytes(), -1);

                await zk.setDataAsync("/foo-" + i, ("foodata3-" + i).UTF8getBytes(), -1);
            }
            for (int i = 0; i < watchers.Length; i++)
            {
                WatchedEvent @event = watchers[i].events.poll(10 * 1000);
                Assert.assertEquals("/foo-" + i, @event.getPath());
                Assert.assertEquals(Watcher.Event.EventType.NodeDataChanged, @event.get_Type());
                Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());

                // small chance that an unexpected message was delivered
                //  after this check, but we would catch that next time
                //  we check events
                Assert.assertEquals(0, watchers[i].events.size());
            }

            //
            // test get/exists with single set of watchers
            //  get/exists together
            //
            for (int i = 0; i < watchers.Length; i++)
            {
                Assert.assertNotNull((await zk.getDataAsync("/foo-" + i, watchers[i])).Data);
                Assert.assertNotNull(await zk.existsAsync("/foo-" + i, watchers[i]));
            }
            // trigger the watches
            for (int i = 0; i < watchers.Length; i++)
            {
                await zk.setDataAsync("/foo-" + i, ("foodata4-" + i).UTF8getBytes(), -1);

                await zk.setDataAsync("/foo-" + i, ("foodata5-" + i).UTF8getBytes(), -1);
            }
            for (int i = 0; i < watchers.Length; i++)
            {
                WatchedEvent @event = watchers[i].events.poll(10 * 1000);
                Assert.assertEquals("/foo-" + i, @event.getPath());
                Assert.assertEquals(Watcher.Event.EventType.NodeDataChanged, @event.get_Type());
                Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());

                // small chance that an unexpected message was delivered
                //  after this check, but we would catch that next time
                //  we check events
                Assert.assertEquals(0, watchers[i].events.size());
            }

            //
            // test get/exists with two sets of watchers
            //
            for (int i = 0; i < watchers.Length; i++)
            {
                Assert.assertNotNull((await zk.getDataAsync("/foo-" + i, watchers[i])).Data);
                Assert.assertNotNull(await zk.existsAsync("/foo-" + i, watchers2[i]));
            }
            // trigger the watches
            for (int i = 0; i < watchers.Length; i++)
            {
                await zk.setDataAsync("/foo-" + i, ("foodata6-" + i).UTF8getBytes(), -1);

                await zk.setDataAsync("/foo-" + i, ("foodata7-" + i).UTF8getBytes(), -1);
            }
            for (int i = 0; i < watchers.Length; i++)
            {
                WatchedEvent @event = watchers[i].events.poll(10 * 1000);
                Assert.assertEquals("/foo-" + i, @event.getPath());
                Assert.assertEquals(Watcher.Event.EventType.NodeDataChanged, @event.get_Type());
                Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, @event.getState());

                // small chance that an unexpected message was delivered
                //  after this check, but we would catch that next time
                //  we check events
                Assert.assertEquals(0, watchers[i].events.size());

                // watchers2
                WatchedEvent event2 = watchers2[i].events.poll(10 * 1000);
                Assert.assertEquals("/foo-" + i, event2.getPath());
                Assert.assertEquals(Watcher.Event.EventType.NodeDataChanged, event2.get_Type());
                Assert.assertEquals(Watcher.Event.KeeperState.SyncConnected, event2.getState());

                // small chance that an unexpected message was delivered
                //  after this check, but we would catch that next time
                //  we check events
                Assert.assertEquals(0, watchers2[i].events.size());
            }
        }
示例#11
0
        public void testChrootSynchronous()
        {
            ZooKeeper zk1 = createClient();

            try
            {
                zk1.create("/ch1", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
            }
            finally
            {
                if (zk1 != null)
                {
                    zk1.close();
                }
            }
            ZooKeeper zk2 = createClient("/ch1");

            try
            {
                Assert.assertEquals("/ch2", zk2.create("/ch2", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
            }
            finally
            {
                if (zk2 != null)
                {
                    zk2.close();
                }
            }

            zk1 = createClient();
            zk2 = createClient("/ch1");
            try
            {
                // check get
                MyWatcher w1 = new MyWatcher("/ch1");
                Assert.assertNotNull(zk1.exists("/ch1", w1));
                MyWatcher w2 = new MyWatcher("/ch1/ch2");
                Assert.assertNotNull(zk1.exists("/ch1/ch2", w2));

                MyWatcher w3 = new MyWatcher("/ch2");
                Assert.assertNotNull(zk2.exists("/ch2", w3));

                // set watches on child
                MyWatcher w4 = new MyWatcher("/ch1");
                zk1.getChildren("/ch1", w4);
                MyWatcher w5 = new MyWatcher("/");
                zk2.getChildren("/", w5);

                // check set
                zk1.setData("/ch1", "1".getBytes(), -1);
                zk2.setData("/ch2", "2".getBytes(), -1);

                // check watches
                Assert.assertTrue(w1.matches());
                Assert.assertTrue(w2.matches());
                Assert.assertTrue(w3.matches());

                // check exceptions
                try
                {
                    zk2.setData("/ch3", "3".getBytes(), -1);
                }
                catch (KeeperException.NoNodeException e)
                {
                    Assert.assertEquals("/ch3", e.getPath());
                }

                Assert.assertEquals("1".getBytes(), zk1.getData("/ch1", false, null));
                Assert.assertEquals("2".getBytes(), zk1.getData("/ch1/ch2", false, null));
                Assert.assertEquals("2".getBytes(), zk2.getData("/ch2", false, null));

                // check delete
                zk2.delete("/ch2", -1);
                Assert.assertTrue(w4.matches());
                Assert.assertTrue(w5.matches());

                zk1.delete("/ch1", -1);
                Assert.assertNull(zk1.exists("/ch1", false));
                Assert.assertNull(zk1.exists("/ch1/ch2", false));
                Assert.assertNull(zk2.exists("/ch2", false));
            }
            finally
            {
                if (zk1 != null)
                {
                    zk1.close();
                }
                if (zk2 != null)
                {
                    zk2.close();
                }
            }
        }
示例#12
0
        private void performClientTest(bool withWatcherObj)
        {
            MyWatcher watcher = new MyWatcher();

            using (var zk = CreateClient(watcher))
            {
                LOG.Info("Before Create /benwashere");
                string benwashere = "/" + Guid.NewGuid() + "benwashere";
                zk.Create(benwashere, "".GetBytes(), Ids.OPEN_ACL_UNSAFE,
                          CreateMode.Persistent);
                LOG.Info("After Create /benwashere");
                try
                {
                    zk.SetData(benwashere, "hi".GetBytes(), 57);
                    Assert.True(false, "Should have gotten BadVersion exception");
                }
                catch (KeeperException.BadVersionException)
                {
                    // expected that
                }
                catch (KeeperException)
                {
                    Assert.True(false, "Should have gotten BadVersion exception");
                }
                LOG.Info("Before Delete /benwashere");
                zk.Delete(benwashere, 0);
                LOG.Info("After Delete /benwashere");
            }

            //LOG.Info("Closed client: " + zk.describeCNXN());
            Thread.Sleep(2000);

            using (var zk = CreateClient(watcher))
            {
                //LOG.Info("Created a new client: " + zk.describeCNXN());
                LOG.Info("Before Delete /");
                try
                {
                    zk.Delete("/", -1);
                    Assert.True(false, "Deleted root!");
                }
                catch (KeeperException.BadArgumentsException)
                {
                    // good, expected that
                }
                Stat stat = new Stat();
                // Test basic Create, ls, and GetData
                string pat        = "/pat" + Guid.NewGuid();
                string patPlusBen = pat + "/ben";
                zk.Create(pat, "Pat was here".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                LOG.Info("Before Create /ben");
                zk.Create(patPlusBen, "Ben was here".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                LOG.Info("Before GetChildren /pat");
                var children = zk.GetChildren(pat, false);
                Assert.Equal(1, children.Count());
                Assert.Equal("ben", children.ElementAt(0));
                var children2 = zk.GetChildren(pat, false, null);
                Assert.Equal(children, children2);

                string value = Encoding.UTF8.GetString(zk.GetData(patPlusBen, false, stat));
                Assert.Equal("Ben was here", value);
                // Test stat and watch of non existent node

                string frog = "/frog" + Guid.NewGuid();
                try
                {
                    if (withWatcherObj)
                    {
                        Assert.Equal(null, zk.Exists(frog, watcher));
                    }
                    else
                    {
                        Assert.Equal(null, zk.Exists(frog, true));
                    }
                    LOG.Info("Comment: asseting passed for frog setting /");
                }
                catch (KeeperException.NoNodeException)
                {
                    // OK, expected that
                }
                zk.Create(frog, "hi".GetBytes(), Ids.OPEN_ACL_UNSAFE,
                          CreateMode.Persistent);
                // the first poll is just a session delivery
                LOG.Info("Comment: checking for events Length "
                         + watcher.events.Count);
                WatchedEvent @event;
                watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3000));
                Assert.Equal(frog, @event.Path);
                Assert.Equal(EventType.NodeCreated, @event.Type);
                Assert.Equal(KeeperState.SyncConnected, @event.State);
                // Test child watch and Create with sequence
                zk.GetChildren(patPlusBen, true);
                for (int i = 0; i < 10; i++)
                {
                    zk.Create(patPlusBen + "/" + i + "-", Convert.ToString(i).GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PersistentSequential);
                }
                children = zk.GetChildren(patPlusBen, false);

                children = children.OrderBy(s => s).ToList();

                Assert.Equal(10, children.Count());
                for (int i = 0; i < 10; i++)
                {
                    string name = children.ElementAt(i);
                    Assert.True(name.StartsWith(i + "-"), "starts with -");
                    byte[] b;
                    if (withWatcherObj)
                    {
                        b = zk.GetData(patPlusBen + "/" + name, watcher, stat);
                    }
                    else
                    {
                        b = zk.GetData(patPlusBen + "/" + name, true, stat);
                    }
                    Assert.Equal(Convert.ToString(i), Encoding.UTF8.GetString(b));
                    zk.SetData(patPlusBen + "/" + name, "new".GetBytes(),
                               stat.Version);
                    if (withWatcherObj)
                    {
                        stat = zk.Exists(patPlusBen + "/" + name, watcher);
                    }
                    else
                    {
                        stat = zk.Exists(patPlusBen + "/" + name, true);
                    }
                    zk.Delete(patPlusBen + "/" + name, stat.Version);
                }

                watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3));
                Assert.Equal(patPlusBen, @event.Path);
                Assert.Equal(EventType.NodeChildrenChanged, @event.Type);
                Assert.Equal(KeeperState.SyncConnected, @event.State);
                for (int i = 0; i < 10; i++)
                {
                    watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3));
                    string name = children.ElementAt(i);
                    Assert.Equal(patPlusBen + "/" + name, @event.Path);
                    Assert.Equal(EventType.NodeDataChanged, @event.Type);
                    Assert.Equal(KeeperState.SyncConnected, @event.State);
                    watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3));
                    Assert.Equal(patPlusBen + "/" + name, @event.Path);
                    Assert.Equal(EventType.NodeDeleted, @event.Type);
                    Assert.Equal(KeeperState.SyncConnected, @event.State);
                }
                zk.Create("/good" + Guid.NewGuid() + "\u0040path", "".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);

                var dup = "/duplicate" + Guid.NewGuid();
                zk.Create(dup, "".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                try
                {
                    zk.Create(dup, "".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                    Assert.True(false, "duplicate Create allowed");
                }
                catch (KeeperException.NodeExistsException)
                {
                    // OK, expected that
                }
            }
        }
示例#13
0
        public void testMutipleWatcherObjs()
        {
            ZooKeeper zk = CreateClient(new CountdownWatcher());

            try
            {
                MyWatcher[] watchers  = new MyWatcher[100];
                MyWatcher[] watchers2 = new MyWatcher[watchers.Length];
                string      name      = "/" + Guid.NewGuid() + "foo-";
                for (int i = 0; i < watchers.Length; i++)
                {
                    watchers[i]  = new MyWatcher();
                    watchers2[i] = new MyWatcher();
                    zk.Create(name + i, ("foodata" + i).GetBytes(),
                              Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                }
                Stat stat = new Stat();

                //
                // test get/Exists with single set of watchers
                //   get all, then Exists all
                //
                for (int i = 0; i < watchers.Length; i++)
                {
                    Assert.NotNull(zk.GetData(name + i, watchers[i], stat));
                }
                for (int i = 0; i < watchers.Length; i++)
                {
                    Assert.NotNull(zk.Exists(name + i, watchers[i]));
                }
                // trigger the watches
                for (int i = 0; i < watchers.Length; i++)
                {
                    zk.SetData(name + i, ("foodata2-" + i).GetBytes(), -1);
                    zk.SetData(name + i, ("foodata3-" + i).GetBytes(), -1);
                }
                for (int i = 0; i < watchers.Length; i++)
                {
                    WatchedEvent @event;
                    watchers[i].events.TryTake(out @event, TimeSpan.FromSeconds(3d));
                    Assert.Equal(name + i, @event.Path);
                    Assert.Equal(EventType.NodeDataChanged, @event.Type);
                    Assert.Equal(KeeperState.SyncConnected, @event.State);

                    // small chance that an unexpected message was delivered
                    //  after this check, but we would catch that next time
                    //  we check events
                    Assert.Equal(0, watchers[i].events.Count);
                }

                //
                // test get/Exists with single set of watchers
                //  get/Exists together
                //
                for (int i = 0; i < watchers.Length; i++)
                {
                    Assert.NotNull(zk.GetData(name + i, watchers[i], stat));
                    Assert.NotNull(zk.Exists(name + i, watchers[i]));
                }
                // trigger the watches
                for (int i = 0; i < watchers.Length; i++)
                {
                    zk.SetData(name + i, ("foodata4-" + i).GetBytes(), -1);
                    zk.SetData(name + i, ("foodata5-" + i).GetBytes(), -1);
                }
                for (int i = 0; i < watchers.Length; i++)
                {
                    WatchedEvent @event;
                    watchers[i].events.TryTake(out @event, TimeSpan.FromSeconds(10d));
                    Assert.Equal(name + i, @event.Path);
                    Assert.Equal(EventType.NodeDataChanged, @event.Type);
                    Assert.Equal(KeeperState.SyncConnected, @event.State);

                    // small chance that an unexpected message was delivered
                    //  after this check, but we would catch that next time
                    //  we check events
                    Assert.Equal(0, watchers[i].events.Count);
                }

                //
                // test get/Exists with two sets of watchers
                //
                for (int i = 0; i < watchers.Length; i++)
                {
                    Assert.NotNull(zk.GetData(name + i, watchers[i], stat));
                    Assert.NotNull(zk.Exists(name + i, watchers2[i]));
                }
                // trigger the watches
                for (int i = 0; i < watchers.Length; i++)
                {
                    zk.SetData(name + i, ("foodata6-" + i).GetBytes(), -1);
                    zk.SetData(name + i, ("foodata7-" + i).GetBytes(), -1);
                }
                for (int i = 0; i < watchers.Length; i++)
                {
                    WatchedEvent @event;
                    watchers[i].events.TryTake(out @event, TimeSpan.FromSeconds(3000));
                    Assert.Equal(name + i, @event.Path);
                    Assert.Equal(EventType.NodeDataChanged, @event.Type);
                    Assert.Equal(KeeperState.SyncConnected, @event.State);

                    // small chance that an unexpected message was delivered
                    //  after this check, but we would catch that next time
                    //  we check events
                    Assert.Equal(0, watchers[i].events.Count);

                    // watchers2
                    WatchedEvent event2;
                    watchers2[i].events.TryTake(out @event2, TimeSpan.FromSeconds(3000));
                    Assert.Equal(name + i, event2.Path);
                    Assert.Equal(EventType.NodeDataChanged, event2.Type);
                    Assert.Equal(KeeperState.SyncConnected, event2.State);

                    // small chance that an unexpected message was delivered
                    //  after this check, but we would catch that next time
                    //  we check events
                    Assert.Equal(0, watchers2[i].events.Count);
                }
            }
            finally
            {
                if (zk != null)
                {
                    zk.Dispose();
                }
            }
        }
示例#14
0
        public void testChrootSynchronous()
        {
            string ch1 = "/" + Guid.NewGuid() + "ch1";

            using (ZooKeeper zk1 = CreateClient())
            {
                Assert.AreEqual(ch1, zk1.Create(ch1, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent));
            }

            string ch2 = "/" + Guid.NewGuid() + "ch2";

            using (ZooKeeper zk2 = CreateClient(ch1))
            {
                Assert.AreEqual(ch2, zk2.Create(ch2, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent));
            }

            using (ZooKeeper zk1 = CreateClient())
                using (ZooKeeper zk2 = CreateClient(ch1))
                {
                    // check get
                    MyWatcher w1 = new MyWatcher("w1", ch1);
                    Assert.NotNull(zk1.Exists(ch1, w1));
                    string    ch1Ch2 = string.Format("{0}{1}", ch1, ch2);
                    MyWatcher w2     = new MyWatcher("w2", ch1Ch2);
                    Assert.NotNull(zk1.Exists(ch1Ch2, w2));

                    MyWatcher w3 = new MyWatcher("w3", ch2);
                    Assert.NotNull(zk2.Exists(ch2, w3));

                    // set watches on child
                    MyWatcher w4 = new MyWatcher("w4", ch1);
                    zk1.GetChildren(ch1, w4);
                    MyWatcher w5 = new MyWatcher("w5", "/");
                    zk2.GetChildren("/", w5);

                    // check set
                    zk1.SetData(ch1, Encoding.UTF8.GetBytes("1"), -1);
                    zk2.SetData(ch2, "2".GetBytes(), -1);

                    // check watches
                    Assert.True(w1.Matches());
                    Assert.True(w2.Matches());
                    Assert.True(w3.Matches());

                    // check exceptions
                    string ch3 = "/" + Guid.NewGuid() + "ch3";
                    try
                    {
                        zk2.SetData(ch3, "3".GetBytes(), -1);
                    }
                    catch (KeeperException.NoNodeException e)
                    {
                        Assert.AreEqual(ch3, e.getPath());
                    }

                    Assert.AreEqual("1".GetBytes(), zk1.GetData(ch1, false, null));
                    Assert.AreEqual("2".GetBytes(), zk1.GetData(ch1Ch2, false, null));
                    Assert.AreEqual("2".GetBytes(), zk2.GetData(ch2, false, null));

                    // check delete
                    zk2.Delete(ch2, -1);
                    Assert.True(w4.Matches());
                    Assert.True(w5.Matches());

                    zk1.Delete(ch1, -1);
                    Assert.Null(zk1.Exists(ch1, false));
                    Assert.Null(zk1.Exists(ch1Ch2, false));
                    Assert.Null(zk2.Exists(ch2, false));
                }
        }
示例#15
0
    public static int Main(string[] args)
    {
        gdcm.FileMetaInformation.SetSourceApplicationEntityTitle("My ClinicalTrial App");

        // http://www.oid-info.com/get/1.3.6.1.4.17434
        string THERALYS_ORG_ROOT = "1.3.6.1.4.17434";

        gdcm.UIDGenerator.SetRoot(THERALYS_ORG_ROOT);
        System.Console.WriteLine("Root dir is now: " + gdcm.UIDGenerator.GetRoot());

        gdcm.Global global = gdcm.Global.GetInstance();
        if (!global.LoadResourcesFiles())
        {
            System.Console.WriteLine("Could not LoadResourcesFiles");
            return(1);
        }

        if (args.Length != 2)
        {
            System.Console.WriteLine("Usage:");
            System.Console.WriteLine("ClinicalTrialIdentificationWorkflow input_dir output_dir");
            return(1);
        }
        string dir1 = args[0];
        string dir2 = args[1];

        // Check input is valid:
        if (!gdcm.PosixEmulation.FileIsDirectory(dir1))
        {
            System.Console.WriteLine("Input directory: " + dir1 + " does not exist. Sorry");
            return(1);
        }
        if (!gdcm.PosixEmulation.FileIsDirectory(dir2))
        {
            System.Console.WriteLine("Output directory: " + dir2 + " does not exist. Sorry");
            return(1);
        }

        // Recursively search all file within this toplevel directory:
        Directory d      = new Directory();
        uint      nfiles = d.Load(dir1, true);

        if (nfiles == 0)
        {
            return(1);
        }

        // Let's use the pre-shipped certificate of GDCM.
        string certpath = gdcm.Filename.Join(gdcm.Testing.GetSourceDirectory(), "/Testing/Source/Data/certificate.pem");

        gdcm.CryptographicMessageSyntax cms = new gdcm.CryptographicMessageSyntax();
        if (!cms.ParseCertificateFile(certpath))
        {
            System.Console.WriteLine("PEM Certificate : " + certpath + " could not be read. Sorry");
            return(1);
        }

        //Anonymizer ano = new Anonymizer();
        // A reference to an actual C++ instance is required here:
        SmartPtrAno sano = Anonymizer.New();
        Anonymizer  ano  = sano.__ref__();

        //SimpleSubjectWatcher watcher = new SimpleSubjectWatcher(ano, "Anonymizer");
        MyWatcher watcher = new MyWatcher(ano);

        // Explicitely specify the Cryptographic Message Syntax to use:
        ano.SetCryptographicMessageSyntax(cms);

        // Process all filenames:
        FilenamesType filenames = d.GetFilenames();

        for (uint i = 0; i < nfiles; ++i)
        {
            string filename    = filenames[(int)i];
            string outfilename = filename.Replace(dir1, dir2);
            System.Console.WriteLine("Filename: " + filename);
            System.Console.WriteLine("Out Filename: " + outfilename);
            if (!ProcessOneFile(ano, filename, outfilename))
            {
                System.Console.WriteLine("Could not process filename: " + filename);
                return(1);
            }
        }

        return(0);
    }
    public static int Main(string[] args)
    {
        gdcm.FileMetaInformation.SetSourceApplicationEntityTitle( "My ClinicalTrial App" );

        // http://www.oid-info.com/get/1.3.6.1.4.17434
        string THERALYS_ORG_ROOT = "1.3.6.1.4.17434";
        gdcm.UIDGenerator.SetRoot( THERALYS_ORG_ROOT );
        System.Console.WriteLine( "Root dir is now: " + gdcm.UIDGenerator.GetRoot() );

        gdcm.Global global = gdcm.Global.GetInstance();
        if( !global.LoadResourcesFiles() )
          {
          System.Console.WriteLine( "Could not LoadResourcesFiles" );
          return 1;
          }

        string dir1 = args[0];
        string dir2 = args[1];

        // Check input is valid:
        if( !gdcm.PosixEmulation.FileIsDirectory(dir1) )
          {
          System.Console.WriteLine( "Input directory: " + dir1 + " does not exist. Sorry" );
          return 1;
          }
        if( !gdcm.PosixEmulation.FileIsDirectory(dir2) )
          {
          System.Console.WriteLine( "Output directory: " + dir2 + " does not exist. Sorry" );
          return 1;
          }

        Directory d = new Directory();
        uint nfiles = d.Load( dir1, true );
        if(nfiles == 0) return 1;

        string certpath = gdcm.Filename.Join(gdcm.Testing.GetSourceDirectory(), "/Testing/Source/Data/certificate.pem" );
        gdcm.CryptographicMessageSyntax cms = new gdcm.CryptographicMessageSyntax();
        if( !cms.ParseCertificateFile( certpath ) )
          {
          return 1;
          }

        //Anonymizer ano = new Anonymizer();
        SmartPtrAno sano = Anonymizer.New();
        Anonymizer ano = sano.__ref__();

        //SimpleSubjectWatcher watcher = new SimpleSubjectWatcher(ano, "Anonymizer");
        MyWatcher watcher = new MyWatcher(ano);

        ano.SetCryptographicMessageSyntax( cms );

        // Process all filenames:
        FilenamesType filenames = d.GetFilenames();
        for( uint i = 0; i < nfiles; ++i )
          {
          string filename = filenames[ (int)i ];
          string outfilename = filename.Replace( dir1, dir2 );
          System.Console.WriteLine( "Filename: " + filename );
          System.Console.WriteLine( "Out Filename: " + outfilename );
          if( !ProcessOneFile( ano , filename, outfilename ) )
        {
        System.Console.WriteLine( "Could not process filename: " + filename );
        return 1;
        }
          }

        return 0;
    }
  public static int Main(string[] args)
    {
    gdcm.FileMetaInformation.SetSourceApplicationEntityTitle( "My ClinicalTrial App" );

    // http://www.oid-info.com/get/1.3.6.1.4.17434
    string THERALYS_ORG_ROOT = "1.3.6.1.4.17434";
    gdcm.UIDGenerator.SetRoot( THERALYS_ORG_ROOT );
    System.Console.WriteLine( "Root dir is now: " + gdcm.UIDGenerator.GetRoot() );

    gdcm.Global global = gdcm.Global.GetInstance();
    if( !global.LoadResourcesFiles() )
      {
      System.Console.WriteLine( "Could not LoadResourcesFiles" );
      return 1;
      }

    if( args.Length != 2 )
      {
      System.Console.WriteLine( "Usage:" );
      System.Console.WriteLine( "ClinicalTrialIdentificationWorkflow input_dir output_dir" );
      return 1;
      }
    string dir1 = args[0];
    string dir2 = args[1];

    // Check input is valid:
    if( !gdcm.PosixEmulation.FileIsDirectory(dir1) )
      {
      System.Console.WriteLine( "Input directory: " + dir1 + " does not exist. Sorry" );
      return 1;
      }
    if( !gdcm.PosixEmulation.FileIsDirectory(dir2) )
      {
      System.Console.WriteLine( "Output directory: " + dir2 + " does not exist. Sorry" );
      return 1;
      }

    // Recursively search all file within this toplevel directory:
    Directory d = new Directory();
    uint nfiles = d.Load( dir1, true );
    if(nfiles == 0) return 1;

    // Let's use the pre-shipped certificate of GDCM.
    string certpath = gdcm.Filename.Join(gdcm.Testing.GetSourceDirectory(), "/Testing/Source/Data/certificate.pem" );
    gdcm.CryptoFactory fact = gdcm.CryptoFactory.GetFactoryInstance();
    gdcm.CryptographicMessageSyntax cms = fact.CreateCMSProvider();
    if( !cms.ParseCertificateFile( certpath ) )
      {
      System.Console.WriteLine( "PEM Certificate : " + certpath + " could not be read. Sorry" );
      return 1;
      }

    //Anonymizer ano = new Anonymizer();
    // A reference to an actual C++ instance is required here:
    SmartPtrAno sano = Anonymizer.New();
    Anonymizer ano = sano.__ref__();

    //SimpleSubjectWatcher watcher = new SimpleSubjectWatcher(ano, "Anonymizer");
    MyWatcher watcher = new MyWatcher(ano);

    // Explicitly specify the Cryptographic Message Syntax to use:
    ano.SetCryptographicMessageSyntax( cms );

    // Process all filenames:
    FilenamesType filenames = d.GetFilenames();
    for( uint i = 0; i < nfiles; ++i )
      {
      string filename = filenames[ (int)i ];
      string outfilename = filename.Replace( dir1, dir2 );
      System.Console.WriteLine( "Filename: " + filename );
      System.Console.WriteLine( "Out Filename: " + outfilename );
      if( !ProcessOneFile( ano , filename, outfilename ) )
        {
        System.Console.WriteLine( "Could not process filename: " + filename );
        return 1;
        }
      }

    return 0;
    }
示例#18
0
        public void testChrootSynchronous()
        {
            string ch1 = "/" + Guid.NewGuid() + "ch1";
            using (ZooKeeper zk1 = CreateClient())
            {
                Assert.AreEqual(ch1, zk1.Create(ch1, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent));
            }

            string ch2 = "/" + Guid.NewGuid() + "ch2";
            using (ZooKeeper zk2 = CreateClient(ch1))
            {
                Assert.AreEqual(ch2, zk2.Create(ch2, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent));
            }

            using (ZooKeeper zk1 = CreateClient())
            using (ZooKeeper zk2 = CreateClient(ch1))
            {
                // check get
                MyWatcher w1 = new MyWatcher("w1", ch1);
                Assert.NotNull(zk1.Exists(ch1, w1));
                string ch1Ch2 = string.Format("{0}{1}", ch1, ch2);
                MyWatcher w2 = new MyWatcher("w2", ch1Ch2);
                Assert.NotNull(zk1.Exists(ch1Ch2, w2));

                MyWatcher w3 = new MyWatcher("w3", ch2);
                Assert.NotNull(zk2.Exists(ch2, w3));

                // set watches on child
                MyWatcher w4 = new MyWatcher("w4", ch1);
                zk1.GetChildren(ch1, w4);
                MyWatcher w5 = new MyWatcher("w5", "/");
                zk2.GetChildren("/", w5);

                // check set
                zk1.SetData(ch1, Encoding.UTF8.GetBytes("1"), -1);
                zk2.SetData(ch2, "2".GetBytes(), -1);

                // check watches
                Assert.True(w1.Matches());
                Assert.True(w2.Matches());
                Assert.True(w3.Matches());

                // check exceptions
                string ch3 = "/" + Guid.NewGuid() + "ch3";
                try
                {
                    zk2.SetData(ch3, "3".GetBytes(), -1);
                }
                catch (KeeperException.NoNodeException e)
                {
                    Assert.AreEqual(ch3, e.getPath());
                }

                Assert.AreEqual("1".GetBytes(), zk1.GetData(ch1, false, null));
                Assert.AreEqual("2".GetBytes(), zk1.GetData(ch1Ch2, false, null));
                Assert.AreEqual("2".GetBytes(), zk2.GetData(ch2, false, null));

                // check delete
                zk2.Delete(ch2, -1);
                Assert.True(w4.Matches());
                Assert.True(w5.Matches());

                zk1.Delete(ch1, -1);
                Assert.Null(zk1.Exists(ch1, false));
                Assert.Null(zk1.Exists(ch1Ch2, false));
                Assert.Null(zk2.Exists(ch2, false));
            }
        }
示例#19
0
        public async Task testChrootSynchronous()
        {
            ZooKeeper zk1 = await createClient();

            await zk1.createAsync("/ch1", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

            await zk1.closeAsync();

            ZooKeeper zk2 = await createClient("/ch1");

            Assert.assertEquals("/ch2", await zk2.createAsync("/ch2", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));

            await zk2.closeAsync();

            zk1 = await createClient();

            zk2 = await createClient("/ch1");

            // check get
            MyWatcher w1 = new MyWatcher("/ch1");

            Assert.assertNotNull(await zk1.existsAsync("/ch1", w1));
            MyWatcher w2 = new MyWatcher("/ch1/ch2");

            Assert.assertNotNull(await zk1.existsAsync("/ch1/ch2", w2));

            MyWatcher w3 = new MyWatcher("/ch2");

            Assert.assertNotNull(await zk2.existsAsync("/ch2", w3));

            // set watches on child
            MyWatcher w4 = new MyWatcher("/ch1");
            await zk1.getChildrenAsync("/ch1", w4);

            MyWatcher w5 = new MyWatcher("/");
            await zk2.getChildrenAsync("/", w5);

            // check set
            await zk1.setDataAsync("/ch1", "1".UTF8getBytes(), -1);

            await zk2.setDataAsync("/ch2", "2".UTF8getBytes(), -1);

            // check watches
            Assert.assertTrue(await w1.matches());
            Assert.assertTrue(await w2.matches());
            Assert.assertTrue(await w3.matches());

            // check exceptions
            try
            {
                await zk2.setDataAsync("/ch3", "3".UTF8getBytes(), -1);
            }
            catch (KeeperException.NoNodeException e)
            {
                Assert.assertEquals("/ch3", e.getPath());
            }

            Assert.assertEquals("1".UTF8getBytes(), (await zk1.getDataAsync("/ch1", false)).Data);
            Assert.assertEquals("2".UTF8getBytes(), (await zk1.getDataAsync("/ch1/ch2", false)).Data);
            Assert.assertEquals("2".UTF8getBytes(), (await zk2.getDataAsync("/ch2", false)).Data);

            // check delete
            await zk2.deleteAsync("/ch2", -1);

            Assert.assertTrue(await w4.matches());
            Assert.assertTrue(await w5.matches());

            await zk1.deleteAsync("/ch1", -1);

            Assert.assertNull(await zk1.existsAsync("/ch1", false));
            Assert.assertNull(await zk1.existsAsync("/ch1/ch2", false));
            Assert.assertNull(await zk2.existsAsync("/ch2", false));
        }
示例#20
0
        private void performClientTest(bool withWatcherObj)
        {
            MyWatcher watcher = new MyWatcher();
            using (var zk = CreateClient(watcher))
            {
                LOG.Info("Before Create /benwashere");
                string benwashere = "/" + Guid.NewGuid() + "benwashere";
                zk.Create(benwashere, "".GetBytes(), Ids.OPEN_ACL_UNSAFE,
                          CreateMode.Persistent);
                LOG.Info("After Create /benwashere");
                try
                {
                    zk.SetData(benwashere, "hi".GetBytes(), 57);
                    Assert.Fail("Should have gotten BadVersion exception");
                }
                catch (KeeperException.BadVersionException e)
                {
                    // expected that
                }
                catch (KeeperException e)
                {
                    Assert.Fail("Should have gotten BadVersion exception");
                }
                LOG.Info("Before Delete /benwashere");
                zk.Delete(benwashere, 0);
                LOG.Info("After Delete /benwashere");
            }

            //LOG.Info("Closed client: " + zk.describeCNXN());
            Thread.Sleep(2000);

            using (var zk = CreateClient(watcher))
            {
                //LOG.Info("Created a new client: " + zk.describeCNXN());
                LOG.Info("Before Delete /");
                try
                {
                    zk.Delete("/", -1);
                    Assert.Fail("Deleted root!");
                }
                catch (KeeperException.BadArgumentsException e)
                {
                    // good, expected that
                }
                Stat stat = new Stat();
                // Test basic Create, ls, and GetData
                string pat = "/pat" + Guid.NewGuid();
                string patPlusBen = pat + "/ben";
                zk.Create(pat, "Pat was here".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                LOG.Info("Before Create /ben");
                zk.Create(patPlusBen, "Ben was here".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                LOG.Info("Before GetChildren /pat");
                List<string> children = zk.GetChildren(pat, false);
                Assert.AreEqual(1, children.Count);
                Assert.AreEqual("ben", children[0]);
                List<string> children2 = zk.GetChildren(pat, false, null);
                Assert.AreEqual(children, children2);

                string value = Encoding.UTF8.GetString(zk.GetData(patPlusBen, false, stat));
                Assert.AreEqual("Ben was here", value);
                // Test stat and watch of non existent node

                string frog = "/frog" + Guid.NewGuid();
                try
                {
                    if (withWatcherObj)
                    {
                        Assert.AreEqual(null, zk.Exists(frog, watcher));
                    }
                    else
                    {
                        Assert.AreEqual(null, zk.Exists(frog, true));
                    }
                    LOG.Info("Comment: asseting passed for frog setting /");
                }
                catch (KeeperException.NoNodeException e)
                {
                    // OK, expected that
                }
                zk.Create(frog, "hi".GetBytes(), Ids.OPEN_ACL_UNSAFE,
                          CreateMode.Persistent);
                // the first poll is just a session delivery
                LOG.Info("Comment: checking for events Length "
                         + watcher.events.Count);
                WatchedEvent @event;
                watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3000));
                Assert.AreEqual(frog, @event.Path);
                Assert.AreEqual(EventType.NodeCreated, @event.Type);
                Assert.AreEqual(KeeperState.SyncConnected, @event.State);
                // Test child watch and Create with sequence
                zk.GetChildren(patPlusBen, true);
                for (int i = 0; i < 10; i++)
                {
                    zk.Create(patPlusBen + "/" + i + "-", Convert.ToString(i).GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PersistentSequential);
                }
                children = zk.GetChildren(patPlusBen, false);

                children = children.OrderBy(s => s).ToList();

                Assert.AreEqual(10, children.Count);
                for (int i = 0; i < 10; i++)
                {
                    string name = children[i];
                    Assert.True(name.StartsWith(i + "-"), "starts with -");
                    byte[] b;
                    if (withWatcherObj)
                    {
                        b = zk.GetData(patPlusBen + "/" + name, watcher, stat);
                    }
                    else
                    {
                        b = zk.GetData(patPlusBen + "/" + name, true, stat);
                    }
                    Assert.AreEqual(Convert.ToString(i), Encoding.UTF8.GetString(b));
                    zk.SetData(patPlusBen + "/" + name, "new".GetBytes(),
                               stat.Version);
                    if (withWatcherObj)
                    {
                        stat = zk.Exists(patPlusBen + "/" + name, watcher);
                    }
                    else
                    {
                        stat = zk.Exists(patPlusBen + "/" + name, true);
                    }
                    zk.Delete(patPlusBen + "/" + name, stat.Version);
                }

                watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3));
                Assert.AreEqual(patPlusBen, @event.Path);
                Assert.AreEqual(EventType.NodeChildrenChanged, @event.Type);
                Assert.AreEqual(KeeperState.SyncConnected, @event.State);
                for (int i = 0; i < 10; i++)
                {
                    watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3));
                    string name = children[i];
                    Assert.AreEqual(patPlusBen + "/" + name, @event.Path);
                    Assert.AreEqual(EventType.NodeDataChanged, @event.Type);
                    Assert.AreEqual(KeeperState.SyncConnected, @event.State);
                    watcher.events.TryTake(out @event, TimeSpan.FromSeconds(3));
                    Assert.AreEqual(patPlusBen + "/" + name, @event.Path);
                    Assert.AreEqual(EventType.NodeDeleted, @event.Type);
                    Assert.AreEqual(KeeperState.SyncConnected, @event.State);
                }
                zk.Create("/good" + Guid.NewGuid() + "\u0040path", "".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);

                var dup = "/duplicate" + Guid.NewGuid();
                zk.Create(dup, "".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                try
                {
                    zk.Create(dup, "".GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                    Assert.Fail("duplicate Create allowed");
                }
                catch (KeeperException.NodeExistsException e)
                {
                    // OK, expected that
                }
            }
        }
示例#21
0
        public void testMutipleWatcherObjs()
        {
            ZooKeeper zk = CreateClient(new CountdownWatcher());
            try
            {
                MyWatcher[] watchers = new MyWatcher[100];
                MyWatcher[] watchers2 = new MyWatcher[watchers.Length];
                string name = "/" + Guid.NewGuid() + "foo-";
                for (int i = 0; i < watchers.Length; i++)
                {
                    watchers[i] = new MyWatcher();
                    watchers2[i] = new MyWatcher();
                    zk.Create(name + i, ("foodata" + i).GetBytes(),
                            Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                }
                Stat stat = new Stat();

                //
                // test get/Exists with single set of watchers
                //   get all, then Exists all
                //
                for (int i = 0; i < watchers.Length; i++)
                {
                    Assert.NotNull(zk.GetData(name + i, watchers[i], stat));
                }
                for (int i = 0; i < watchers.Length; i++)
                {
                    Assert.NotNull(zk.Exists(name + i, watchers[i]));
                }
                // trigger the watches
                for (int i = 0; i < watchers.Length; i++)
                {
                    zk.SetData(name + i, ("foodata2-" + i).GetBytes(), -1);
                    zk.SetData(name + i, ("foodata3-" + i).GetBytes(), -1);
                }
                for (int i = 0; i < watchers.Length; i++)
                {
                    WatchedEvent @event;
                    watchers[i].events.TryTake(out @event, TimeSpan.FromSeconds(3d));
                    Assert.AreEqual(name + i, @event.Path);
                    Assert.AreEqual(EventType.NodeDataChanged, @event.Type);
                    Assert.AreEqual(KeeperState.SyncConnected, @event.State);

                    // small chance that an unexpected message was delivered
                    //  after this check, but we would catch that next time
                    //  we check events
                    Assert.AreEqual(0, watchers[i].events.Count);
                }

                //
                // test get/Exists with single set of watchers
                //  get/Exists together
                //
                for (int i = 0; i < watchers.Length; i++)
                {
                    Assert.NotNull(zk.GetData(name + i, watchers[i], stat));
                    Assert.NotNull(zk.Exists(name + i, watchers[i]));
                }
                // trigger the watches
                for (int i = 0; i < watchers.Length; i++)
                {
                    zk.SetData(name + i, ("foodata4-" + i).GetBytes(), -1);
                    zk.SetData(name + i, ("foodata5-" + i).GetBytes(), -1);
                }
                for (int i = 0; i < watchers.Length; i++)
                {
                    WatchedEvent @event;
                    watchers[i].events.TryTake(out @event, TimeSpan.FromSeconds(10d));
                    Assert.AreEqual(name + i, @event.Path);
                    Assert.AreEqual(EventType.NodeDataChanged, @event.Type);
                    Assert.AreEqual(KeeperState.SyncConnected, @event.State);

                    // small chance that an unexpected message was delivered
                    //  after this check, but we would catch that next time
                    //  we check events
                    Assert.AreEqual(0, watchers[i].events.Count);
                }

                //
                // test get/Exists with two sets of watchers
                //
                for (int i = 0; i < watchers.Length; i++)
                {
                    Assert.NotNull(zk.GetData(name + i, watchers[i], stat));
                    Assert.NotNull(zk.Exists(name + i, watchers2[i]));
                }
                // trigger the watches
                for (int i = 0; i < watchers.Length; i++)
                {
                    zk.SetData(name + i, ("foodata6-" + i).GetBytes(), -1);
                    zk.SetData(name + i, ("foodata7-" + i).GetBytes(), -1);
                }
                for (int i = 0; i < watchers.Length; i++)
                {
                    WatchedEvent @event;
                    watchers[i].events.TryTake(out @event, TimeSpan.FromSeconds(3000));
                    Assert.AreEqual(name + i, @event.Path);
                    Assert.AreEqual(EventType.NodeDataChanged, @event.Type);
                    Assert.AreEqual(KeeperState.SyncConnected, @event.State);

                    // small chance that an unexpected message was delivered
                    //  after this check, but we would catch that next time
                    //  we check events
                    Assert.AreEqual(0, watchers[i].events.Count);

                    // watchers2
                    WatchedEvent event2;
                    watchers2[i].events.TryTake(out @event2, TimeSpan.FromSeconds(3000));
                    Assert.AreEqual(name + i, event2.Path);
                    Assert.AreEqual(EventType.NodeDataChanged, event2.Type);
                    Assert.AreEqual(KeeperState.SyncConnected, event2.State);

                    // small chance that an unexpected message was delivered
                    //  after this check, but we would catch that next time
                    //  we check events
                    Assert.AreEqual(0, watchers2[i].events.Count);
                }

            }
            finally
            {
                if (zk != null)
                {
                    zk.Dispose();
                }
            }
        }