Package org.apache.hadoop.hdfs.notifier.server

Examples of org.apache.hadoop.hdfs.notifier.server.ServerCore


 
  @Test
  public void testSimpleClient() throws TException, InterruptedException,
            TransactionIdTooOldException, NotConnectedToServerException, 
            WatchAlreadyPlacedException, IOException {
    ServerCore notifier = null;
   
    try {
      String editPath = conf.get(AvatarNode.DFS_SHARED_EDITS_DIR0_KEY);
      LOG.info("edit path: " + editPath);
      File file = new File(editPath);
      String[] names = file.list();
      for (String name : names) {
        LOG.info("content: " + name);
      }
    
      conf.setLong(NotifierConfig.LOG_READER_STREAM_TIMEOUT, 100);
     
      notifier = ServerCore.createNotifier(conf, nameService);
     
      int port = conf.getInt("notifier.thrift.port", -1);
      int clientPort = MiniDFSCluster.getFreePort();
      LOG.info("port: " + port);
      MyClientWatcher myWatcher = new MyClientWatcher();
      NamespaceNotifierClient myClient = new NamespaceNotifierClient(myWatcher,
          localhostAddr, port, clientPort);
      Thread clientThread = new Thread(myClient);
      clientThread.start();
     
      // wait for connect
      long start = System.currentTimeMillis();
      while (!myWatcher.connected &&
            System.currentTimeMillis() < start + 2000) {
        Thread.sleep(500);
      }
     
      myClient.placeWatch("/", EventType.FILE_ADDED, -1);
      myClient.placeWatch("/", EventType.FILE_CLOSED, -1);
      myClient.placeWatch("/", EventType.NODE_DELETED, -1);
     
      int numRequests = random.nextInt(50) + 1;
      // issue number of requests.
      for (int i = 0; i < numRequests; i++) {
        FSDataOutputStream out = fileSys.create(new Path("/testfile_" + i));
        out.close();
      }
     
      LOG.info("Start failover");
      cluster.failOver();
      cluster.restartStandby();
      Thread.sleep(100);
     
      for (int i = 0; i < numRequests; i++) {
        fileSys.delete(new Path("/testfile_" + i), false);
      }
     
      start = System.currentTimeMillis();
      while (myWatcher.numDeleted < numRequests &&
          System.currentTimeMillis() < start + 6000) {
        Thread.sleep(500);
      }
     
      assertEquals(numRequests, myWatcher.numAdd);
      assertEquals(numRequests, myWatcher.numClosed);
      assertEquals(numRequests, myWatcher.numDeleted);
     
      // check the events from sub directors.
      myWatcher.resetCounters();
      // issue number of requests.
      for (int i = 0; i < numRequests; i++) {
        FSDataOutputStream out = fileSys.create(new Path("/user/dikang/testfile_" + i));
        out.close();
      }
    
      LOG.info("Start failover");
      cluster.failOver();
      cluster.restartStandby();
      Thread.sleep(100);
     
      for (int i = 0; i < numRequests; i++) {
        fileSys.delete(new Path("/user/dikang/testfile_" + i), false);
      }
     
      start = System.currentTimeMillis();
      while (myWatcher.numDeleted < numRequests &&
          System.currentTimeMillis() < start + 6000) {
        Thread.sleep(500);
      }
     
      assertEquals(numRequests, myWatcher.numAdd);
      assertEquals(numRequests, myWatcher.numClosed);
      assertEquals(numRequests, myWatcher.numDeleted);
     
     
    } finally {
      if (notifier != null) {
        notifier.shutdown();
        notifier.join();
      }
    }
  }
View Full Code Here


  @Test
  public void testDirOps() throws IOException, InterruptedException,
                            TException, TransactionIdTooOldException,
                            NotConnectedToServerException,
                            WatchAlreadyPlacedException {
    ServerCore notifier = null;
   
    try {
      String editPath = conf.get(AvatarNode.DFS_SHARED_EDITS_DIR0_KEY);
      File file = new File(editPath);
      String[] names = file.list();
      for (String name : names) {
        LOG.info("content: " + name);
      }
     
      notifier = ServerCore.createNotifier(conf, nameService);
     
      int port = conf.getInt("notifier.thrift.port", -1);
      int clientPort = MiniDFSCluster.getFreePort();
      LOG.info("port: " + port);
      MyClientWatcher myWatcher = new MyClientWatcher();
      NamespaceNotifierClient myClient = new NamespaceNotifierClient(myWatcher,
          localhostAddr, port, clientPort);
      Thread clientThread = new Thread(myClient);
      clientThread.start();
     
      // wait for connect
      long start = System.currentTimeMillis();
      while (!myWatcher.connected &&
            System.currentTimeMillis() < start + 2000) {
        Thread.sleep(500);
      }
     
      myClient.placeWatch("/", EventType.NODE_DELETED, -1);
      myClient.placeWatch("/", EventType.DIR_ADDED, -1);
     
      int numRequests = random.nextInt(50) + 1;
      // issue number of requests.
      for (int i = 0; i < numRequests; i++) {
        FSDataOutputStream out = fileSys.create(new Path("/testDir_" + i + "/file"));
        out.close();
      }
     
      for (int i = 0; i < numRequests; i++) {
        fileSys.delete(new Path("/testDir_" + i), true);
      }
     
      start = System.currentTimeMillis();
      while (myWatcher.numDeleted < numRequests &&
          System.currentTimeMillis() < start + 6000) {
        Thread.sleep(500);
      }
     
      assertEquals(numRequests, myWatcher.numDirAdded);
      assertEquals(numRequests, myWatcher.numDeleted);
    } finally {
      if (notifier != null) {
        notifier.shutdown();
        notifier.join();
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hdfs.notifier.server.ServerCore

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.