Package org.apache.flink.api.common.io

Examples of org.apache.flink.api.common.io.LocatableInputSplitAssigner


    return true;
  }

  @Override
  public InputSplitAssigner getInputSplitAssigner(TableInputSplit[] inputSplits) {
    return new LocatableInputSplitAssigner(inputSplits);
  }
View Full Code Here


      for (int i = 0; i < NUM_SPLITS; i++) {
        splits.add(new LocatableInputSplit(i, hosts[i%3]));
      }
     
      // get all available splits
      LocatableInputSplitAssigner ia = new LocatableInputSplitAssigner(splits);
      InputSplit is = null;
      while ((is = ia.getNextInputSplit(null)) != null) {
        assertTrue(splits.remove(is));
      }
     
      // check we had all
      assertTrue(splits.isEmpty());
      assertNull(ia.getNextInputSplit(""));
      assertEquals(NUM_SPLITS, ia.getNumberOfRemoteAssignments());
      assertEquals(0, ia.getNumberOfLocalAssignments());
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
View Full Code Here

      for (int i = 0; i < NUM_SPLITS; i++) {
        splits.add(new LocatableInputSplit(i, "testhost"));
      }
     
      // get all available splits
      LocatableInputSplitAssigner ia = new LocatableInputSplitAssigner(splits);
      InputSplit is = null;
      while ((is = ia.getNextInputSplit("testhost")) != null) {
        assertTrue(splits.remove(is));
      }
     
      // check we had all
      assertTrue(splits.isEmpty());
      assertNull(ia.getNextInputSplit(""));
     
      assertEquals(0, ia.getNumberOfRemoteAssignments());
      assertEquals(NUM_SPLITS, ia.getNumberOfLocalAssignments());
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
View Full Code Here

      for (int i = 0; i < NUM_SPLITS; i++) {
        splits.add(new LocatableInputSplit(i, hosts[i % hosts.length]));
      }
     
      // get all available splits
      LocatableInputSplitAssigner ia = new LocatableInputSplitAssigner(splits);
      InputSplit is = null;
      while ((is = ia.getNextInputSplit("testhost")) != null) {
        assertTrue(splits.remove(is));
      }
     
      // check we had all
      assertTrue(splits.isEmpty());
      assertNull(ia.getNextInputSplit("anotherHost"));
     
      assertEquals(NUM_SPLITS, ia.getNumberOfRemoteAssignments());
      assertEquals(0, ia.getNumberOfLocalAssignments());
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
View Full Code Here

      for (int i = 0; i < NUM_SPLITS; i++) {
        splits.add(new LocatableInputSplit(i, hosts[i % hosts.length]));
      }
     
      // get all available splits
      LocatableInputSplitAssigner ia = new LocatableInputSplitAssigner(splits);
      InputSplit is = null;
      int i = 0;
      while ((is = ia.getNextInputSplit(hosts[i++ % hosts.length])) != null) {
        assertTrue(splits.remove(is));
      }
     
      // check we had all
      assertTrue(splits.isEmpty());
      assertNull(ia.getNextInputSplit("anotherHost"));
     
      assertEquals(0, ia.getNumberOfRemoteAssignments());
      assertEquals(NUM_SPLITS, ia.getNumberOfLocalAssignments());
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
View Full Code Here

      Set<LocatableInputSplit> splits = new HashSet<LocatableInputSplit>();
      for (int i = 0; i < NUM_SPLITS; i++) {
        splits.add(new LocatableInputSplit(i, hosts[i%3]));
      }
     
      final LocatableInputSplitAssigner ia = new LocatableInputSplitAssigner(splits);
     
      final AtomicInteger splitsRetrieved = new AtomicInteger(0);
      final AtomicInteger sumOfIds = new AtomicInteger(0);
     
      Runnable retriever = new Runnable() {
       
        @Override
        public void run() {
          LocatableInputSplit split;
          while ((split = ia.getNextInputSplit(null)) != null) {
            splitsRetrieved.incrementAndGet();
            sumOfIds.addAndGet(split.getSplitNumber());
          }
        }
      };
     
      // create the threads
      Thread[] threads = new Thread[NUM_THREADS];
      for (int i = 0; i < NUM_THREADS; i++) {
        threads[i] = new Thread(retriever);
        threads[i].setDaemon(true);
      }
     
      // launch concurrently
      for (int i = 0; i < NUM_THREADS; i++) {
        threads[i].start();
      }
     
      // sync
      for (int i = 0; i < NUM_THREADS; i++) {
        threads[i].join(5000);
      }
     
      // verify
      for (int i = 0; i < NUM_THREADS; i++) {
        if (threads[i].isAlive()) {
          fail("The concurrency test case is erroneous, the thread did not respond in time.");
        }
      }
     
      assertEquals(NUM_SPLITS, splitsRetrieved.get());
      assertEquals(SUM_OF_IDS, sumOfIds.get());
     
      // nothing left
      assertNull(ia.getNextInputSplit(""));
     
      assertEquals(NUM_SPLITS, ia.getNumberOfRemoteAssignments());
      assertEquals(0, ia.getNumberOfLocalAssignments());
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
View Full Code Here

      Set<LocatableInputSplit> splits = new HashSet<LocatableInputSplit>();
      for (int i = 0; i < NUM_SPLITS; i++) {
        splits.add(new LocatableInputSplit(i, "testhost"));
      }
     
      final LocatableInputSplitAssigner ia = new LocatableInputSplitAssigner(splits);
     
      final AtomicInteger splitsRetrieved = new AtomicInteger(0);
      final AtomicInteger sumOfIds = new AtomicInteger(0);
     
      Runnable retriever = new Runnable() {
       
        @Override
        public void run() {
          LocatableInputSplit split;
          while ((split = ia.getNextInputSplit("testhost")) != null) {
            splitsRetrieved.incrementAndGet();
            sumOfIds.addAndGet(split.getSplitNumber());
          }
        }
      };
     
      // create the threads
      Thread[] threads = new Thread[NUM_THREADS];
      for (int i = 0; i < NUM_THREADS; i++) {
        threads[i] = new Thread(retriever);
        threads[i].setDaemon(true);
      }
     
      // launch concurrently
      for (int i = 0; i < NUM_THREADS; i++) {
        threads[i].start();
      }
     
      // sync
      for (int i = 0; i < NUM_THREADS; i++) {
        threads[i].join(5000);
      }
     
      // verify
      for (int i = 0; i < NUM_THREADS; i++) {
        if (threads[i].isAlive()) {
          fail("The concurrency test case is erroneous, the thread did not respond in time.");
        }
      }
     
      assertEquals(NUM_SPLITS, splitsRetrieved.get());
      assertEquals(SUM_OF_IDS, sumOfIds.get());
     
      // nothing left
      assertNull(ia.getNextInputSplit("testhost"));
     
      assertEquals(0, ia.getNumberOfRemoteAssignments());
      assertEquals(NUM_SPLITS, ia.getNumberOfLocalAssignments());
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
View Full Code Here

      Set<LocatableInputSplit> splits = new HashSet<LocatableInputSplit>();
      for (int i = 0; i < NUM_SPLITS; i++) {
        splits.add(new LocatableInputSplit(i, hosts[i%hosts.length]));
      }
     
      final LocatableInputSplitAssigner ia = new LocatableInputSplitAssigner(splits);
     
      final AtomicInteger splitsRetrieved = new AtomicInteger(0);
      final AtomicInteger sumOfIds = new AtomicInteger(0);
     
      Runnable retriever = new Runnable() {
       
        @Override
        public void run() {
          final String threadHost = hosts[(int) (Math.random() * hosts.length)];
         
          LocatableInputSplit split;
          while ((split = ia.getNextInputSplit(threadHost)) != null) {
            splitsRetrieved.incrementAndGet();
            sumOfIds.addAndGet(split.getSplitNumber());
          }
        }
      };
     
      // create the threads
      Thread[] threads = new Thread[NUM_THREADS];
      for (int i = 0; i < NUM_THREADS; i++) {
        threads[i] = new Thread(retriever);
        threads[i].setDaemon(true);
      }
     
      // launch concurrently
      for (int i = 0; i < NUM_THREADS; i++) {
        threads[i].start();
      }
     
      // sync
      for (int i = 0; i < NUM_THREADS; i++) {
        threads[i].join(5000);
      }
     
      // verify
      for (int i = 0; i < NUM_THREADS; i++) {
        if (threads[i].isAlive()) {
          fail("The concurrency test case is erroneous, the thread did not respond in time.");
        }
      }
     
      assertEquals(NUM_SPLITS, splitsRetrieved.get());
      assertEquals(SUM_OF_IDS, sumOfIds.get());
     
      // nothing left
      assertNull(ia.getNextInputSplit("testhost"));
     
      // at least one fraction of hosts needs be local, no matter how bad the thread races
      assertTrue(ia.getNumberOfLocalAssignments() >= NUM_SPLITS / hosts.length);
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
View Full Code Here

TOP

Related Classes of org.apache.flink.api.common.io.LocatableInputSplitAssigner

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.