Package com.nokia.dempsy.config

Examples of com.nokia.dempsy.config.ClusterId


      runAllCombinations(new Checker()
      {
         @Override
         public void check(String pass, ClusterInfoSessionFactory factory) throws Throwable
         {
            ClusterId cid = new ClusterId("test-app3","testSimpleClusterLevelDataThroughApplication");
           
            ClusterInfoSession session = factory.createSession();
            assertNotNull(pass,session);
            sessionsToClose.add(session);
            String mpapp = createApplicationLevel(cid,session);
            String clusterPath = mpapp + "/" + cid.getMpClusterName();
            assertNotNull(pass,session.mkdir(clusterPath, "YoDude", DirMode.PERSISTENT));
            assertNotNull(pass,clusterPath);
            Collection<String> clusterPaths = session.getSubdirs(mpapp,null);
            assertNotNull(pass,clusterPaths);
            assertEquals(1,clusterPaths.size());
            assertEquals(cid.getMpClusterName(),clusterPaths.iterator().next());

            String data = "HelloThere";
            session.setData(clusterPath,data);
            String cdata = (String)session.getData(clusterPath,null);
            assertEquals(pass,data,cdata);
View Full Code Here


      runAllCombinations(new Checker()
      {
         @Override
         public void check(String pass, ClusterInfoSessionFactory factory) throws Throwable
         {
            ClusterId cid = new ClusterId("test-app4","test-cluster");

            final ClusterInfoSession session = factory.createSession();
            assertNotNull(pass,session);
            sessionsToClose.add(session);
            String cluster = createClusterLevel(cid,session);
View Full Code Here

      runAllCombinations(new Checker()
      {
         @Override
         public void check(String pass, ClusterInfoSessionFactory factory) throws Throwable
         {
            ClusterId cid = new ClusterId("test-app5","test-cluster");
           
            ClusterInfoSession mainSession = factory.createSession();
            assertNotNull(pass,mainSession);           
            sessionsToClose.add(mainSession);
           
            TestWatcher mainAppWatcher = new TestWatcher(1);
            String mpapp = createApplicationLevel(cid,mainSession);
            assertTrue(mainSession.exists(mpapp,null));
            mainSession.getSubdirs(mpapp, mainAppWatcher); // register mainAppWatcher for subdir
            assertEquals(0,mainSession.getSubdirs(mpapp,null).size());
           
            ClusterInfoSession otherSession = factory.createSession();
            assertNotNull(pass,otherSession);
            sessionsToClose.add(otherSession);
           
            assertFalse(pass,mainSession.equals(otherSession));
           
            String clusterHandle = mpapp + "/" + cid.getMpClusterName();
            mainSession.mkdir(clusterHandle,"YoDude",DirMode.PERSISTENT);
            assertTrue(pass,mainSession.exists(clusterHandle,null));
           
            assertTrue(poll(5000, mainAppWatcher, new Condition<TestWatcher>() {
               public boolean conditionMet(TestWatcher o) { return o.recdUpdate;  }
View Full Code Here

      runAllCombinations(new Checker()
      {
         @Override
         public void check(String pass,ClusterInfoSessionFactory factory) throws Throwable
         {
            final ClusterId cid = new ClusterId("test-app6","test-cluster");
            session1 = factory.createSession();
            createClusterLevel(cid, session1);
            sessionsToClose.add(session1);
            session2 = factory.createSession();
            sessionsToClose.add(session2);
View Full Code Here

      runAllCombinations(new Checker()
      {
         @Override
         public void check(String pass, ClusterInfoSessionFactory factory) throws Throwable
         {
            ClusterId cid = new ClusterId("test-app7","test-cluster");

            final ClusterInfoSession session = factory.createSession();
            assertNotNull(pass,session);
            sessionsToClose.add(session);
            String cluster = createClusterLevel(cid,session);
View Full Code Here

      runAllCombinations(new Checker()
      {
         @Override
         public void check(String pass, ClusterInfoSessionFactory factory) throws Throwable
         {
            final ClusterId cid = new ClusterId("test-app2","testNullWatcherBehavior");
            final AtomicBoolean processCalled = new AtomicBoolean(false);
            final ClusterInfoSession session = factory.createSession();
           
            assertNotNull(pass,session);
            sessionsToClose.add(session);
            String clusterPath = createClusterLevel(cid,session);
            assertNotNull(pass,clusterPath);
           
            ClusterInfoWatcher watcher = new ClusterInfoWatcher()
            {
               @Override
               public void process()
               {
                  processCalled.set(true);
               }
            };
           
            assertTrue(session.exists(cid.asPath(), watcher));

            String data = "HelloThere";
            session.setData(clusterPath,data);
           
            assertTrue(poll(5000, null, new Condition<Object>()
View Full Code Here

   @Test
   public void testBouncingServer() throws Throwable
   {
      ZookeeperTestServer server = new ZookeeperTestServer();
      ZookeeperSession session = null;
      final ClusterId clusterId = new ClusterId(appname,"testBouncingServer");
     
      try
      {
         server.start();

         ZookeeperSessionFactory factory = new ZookeeperSessionFactory("127.0.0.1:" + port,5000);
         session = (ZookeeperSession)factory.createSession();
         final ZookeeperSession cluster = session;
         createClusterLevel(clusterId, session);
         TestWatcher callback = new TestWatcher(cluster)
         {
           
            @Override
            public void process()
            {
               boolean done = false;
               while (!done)
               {
                  done = true;
                 
                  try
                  {
                     if (session.getSubdirs(clusterId.asPath(), this).size() == 0)
                        session.mkdir(clusterId.asPath() + "/slot1",null,DirMode.EPHEMERAL);
                     called.set(true);
                  }
                  catch(ClusterInfoException.NoNodeException e)
                  {
                     try
                     {
                        createClusterLevel(clusterId,session);
                        done = false;
                     }
                     catch (ClusterInfoException e1)
                     {
                        throw new RuntimeException(e1);
                     }
                  }
                  catch(ClusterInfoException e)
                  {
                     // this will fail when the connection is severed... that's ok.
                  }
               }
            }

         };

         cluster.exists(clusterId.asPath(), callback);
         callback.process();
        
         // create another session and look
         ZookeeperSession session2 = (ZookeeperSession)factory.createSession();
         assertEquals(1,session2.getSubdirs(new ClusterId(appname,"testBouncingServer").asPath(), null).size());
         session2.stop();

         // kill the server.
         server.shutdown(false);

         // reset the flags
         callback.called.set(false);

         // restart the server
         server.start(false);
        
         // wait for the call
         assertTrue(TestUtils.poll(baseTimeoutMillis, callback, new TestUtils.Condition<TestWatcher>()
         {
            @Override
            public boolean conditionMet(TestWatcher o) { return o.called.get(); }
         }));

         // get the view from a new session.
         session2 = (ZookeeperSession)factory.createSession();
         assertEquals(1,session2.getSubdirs(new ClusterId(appname,"testBouncingServer").asPath(), null).size());
         session2.stop();
      }
      finally
      {
         if (server != null)
View Full Code Here

   @Test
   public void testBouncingServerWithCleanDataDir() throws Throwable
   {
      ZookeeperTestServer server = new ZookeeperTestServer();
      ZookeeperSession session = null;
      final ClusterId clusterId = new ClusterId(appname,"testBouncingServerWithCleanDataDir");
     
      try
      {
         server.start();

         ZookeeperSessionFactory factory = new ZookeeperSessionFactory("127.0.0.1:" + port,5000);
         session = (ZookeeperSession)factory.createSession();
         final ZookeeperSession cluster = session;
         createClusterLevel(clusterId, session);
         TestWatcher callback = new TestWatcher(cluster)
         {
           
            @Override
            public void process()
            {
               boolean done = false;
               while (!done)
               {
                  done = true;
                 
                  try
                  {
                     if (session.getSubdirs(clusterId.asPath(), this).size() == 0)
                        session.mkdir(clusterId.asPath() + "/slot1",null,DirMode.EPHEMERAL);
                     called.set(true);
                  }
                  catch(ClusterInfoException.NoNodeException e)
                  {
                     try
                     {
                        createClusterLevel(clusterId,session);
                        done = false;
                     }
                     catch (ClusterInfoException e1)
                     {
                        throw new RuntimeException(e1);
                     }
                  }
                  catch(ClusterInfoException e)
                  {
                     // this will fail when the connection is severed... that's ok.
                  }
               }
            }

         };

         cluster.exists(clusterId.asPath(), callback);
         callback.process();
        
         // create another session and look
         ZookeeperSession session2 = (ZookeeperSession)factory.createSession();
         assertEquals(1,session2.getSubdirs(new ClusterId(appname,"testBouncingServerWithCleanDataDir").asPath(), null).size());
         session2.stop();

         // kill the server.
         server.shutdown(true);

         // reset the flags
         callback.called.set(false);

         // restart the server
         server.start(true);
        
         // wait for the call
         assertTrue(TestUtils.poll(baseTimeoutMillis, callback, new TestUtils.Condition<TestWatcher>()
         {
            @Override
            public boolean conditionMet(TestWatcher o) { return o.called.get(); }
         }));

         // get the view from a new session.
         session2 = (ZookeeperSession)factory.createSession();
         assertEquals(1,session2.getSubdirs(new ClusterId(appname,"testBouncingServerWithCleanDataDir").asPath(), null).size());
         session2.stop();
      }
      finally
      {
         if (server != null)
View Full Code Here

      ZookeeperSessionFactory factory = new ZookeeperSessionFactory("127.0.0.1:" + port,5000);
     
      // create a session from the session factory
      ZookeeperSession session = (ZookeeperSession)factory.createSession();
     
      ClusterId clusterId = new ClusterId(appname,"testNoServerOnStartup");
     
      // hook a test watch to make sure that callbacks work correctly
      TestWatcher callback = new TestWatcher(session)
      {
         @Override public void process() { called.set(true); }
      };
     
      // now accessing the cluster should get us an error.
      boolean gotCorrectError = false;
      try { session.getSubdirs(clusterId.asPath(), callback); } catch (ClusterInfoException e) { gotCorrectError = true; }
      assertTrue(gotCorrectError);
     
      // now lets startup the server.
      ZookeeperTestServer server = null;
      try
      {
         server = new ZookeeperTestServer();
         server.start();
        
         // create a cluster from the session
         TestUtils.createClusterLevel(clusterId,session);
        
         // wait until this works.
         assertTrue(TestUtils.poll(baseTimeoutMillis, callback, new Condition<TestWatcher>() {
            @Override public boolean conditionMet(TestWatcher o){  return o.called.get(); }
         }));
        
         callback.called.set(false); // reset the callbacker ...
        
         // now see if the cluster works.
         assertTrue(TestUtils.poll(baseTimeoutMillis, callback, new Condition<TestWatcher>() {
            @Override public boolean conditionMet(TestWatcher o){  return !o.called.get(); }
         }));

         session.getSubdirs(clusterId.asPath(), callback);
        
         ZooKeeper origZk = session.zkref.get();
         ZookeeperTestServer.forceSessionExpiration(origZk);
        
         // wait for the callback
         assertTrue(TestUtils.poll(baseTimeoutMillis, callback, new Condition<TestWatcher>() {
            @Override public boolean conditionMet(TestWatcher o){  return o.called.get(); }
         }));
        
         // unfortunately I cannot check the getActiveSlots for failure because there's a race condition I can't fix.
         //  No matter how fast I check it's possible that it's okay again OR that allSlots hasn't been cleared.
         //
         // however, they should eventually recover.
         gotCorrectError = true;
         for (long endTime = System.currentTimeMillis() + baseTimeoutMillis; endTime > System.currentTimeMillis() && gotCorrectError;)
         {
            Thread.sleep(1);
            try { session.getSubdirs(clusterId.asPath(), callback); gotCorrectError = false; } catch (ClusterInfoException e) {  }
         }

         session.getSubdirs(clusterId.asPath(), callback);

         // And join should work
         gotCorrectError = true;
         for (long endTime = System.currentTimeMillis() + baseTimeoutMillis; endTime > System.currentTimeMillis() && gotCorrectError;)
         {
            Thread.sleep(1);
            try { session.mkdir(clusterId.asPath() + "/join-1", null, DirMode.EPHEMERAL); gotCorrectError = false; } catch (ClusterInfoException e) {  }
         }
        
         assertFalse(gotCorrectError);
      }
      finally
View Full Code Here

TOP

Related Classes of com.nokia.dempsy.config.ClusterId

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.