Package org.apache.hadoop.test.MultithreadedTestUtil

Examples of org.apache.hadoop.test.MultithreadedTestUtil.TestingThread


       * Verify that it handles interrupted threads properly.
       * Use a large timeout and expect the thread to return quickly
       * upon interruption.
       */
      ((SocketInputStream)in).setTimeout(0);
      TestingThread thread = new TestingThread(ctx) {
        @Override
        public void doWork() throws Exception {
          try {
            in.read();
            fail("Did not fail with interrupt");
          } catch (InterruptedIOException ste) {
            LOG.info("Got expection while reading as expected : " +
                ste.getMessage());
          }
        }
      };
      ctx.addThread(thread);
      ctx.startThreads();
      // If the thread is interrupted before it calls read()
      // then it throws ClosedByInterruptException due to
      // some Java quirk. Waiting for it to call read()
      // gets it into select(), so we get the expected
      // InterruptedIOException.
      Thread.sleep(1000);
      thread.interrupt();
      ctx.stop();

      //make sure the channels are still open
      assertTrue(source.isOpen());
      assertTrue(sink.isOpen());
View Full Code Here


       * Verify that it handles interrupted threads properly.
       * Use a large timeout and expect the thread to return quickly
       * upon interruption.
       */
      ((SocketInputStream)in).setTimeout(0);
      TestingThread thread = new TestingThread(ctx) {
        @Override
        public void doWork() throws Exception {
          try {
            in.read();
            fail("Did not fail with interrupt");
          } catch (InterruptedIOException ste) {
            LOG.info("Got expection while reading as expected : " +
                ste.getMessage());
          }
        }
      };
      ctx.addThread(thread);
      ctx.startThreads();
      // If the thread is interrupted before it calls read()
      // then it throws ClosedByInterruptException due to
      // some Java quirk. Waiting for it to call read()
      // gets it into select(), so we get the expected
      // InterruptedIOException.
      Thread.sleep(1000);
      thread.interrupt();
      ctx.stop();

      //make sure the channels are still open
      assertTrue(source.isOpen());
      assertTrue(sink.isOpen());
View Full Code Here

       * Verify that it handles interrupted threads properly.
       * Use a large timeout and expect the thread to return quickly
       * upon interruption.
       */
      ((SocketInputStream)in).setTimeout(0);
      TestingThread thread = new TestingThread(ctx) {
        @Override
        public void doWork() throws Exception {
          try {
            in.read();
            fail("Did not fail with interrupt");
          } catch (InterruptedIOException ste) {
            LOG.info("Got expection while reading as expected : " +
                ste.getMessage());
          }
        }
      };
      ctx.addThread(thread);
      ctx.startThreads();
      // If the thread is interrupted before it calls read()
      // then it throws ClosedByInterruptException due to
      // some Java quirk. Waiting for it to call read()
      // gets it into select(), so we get the expected
      // InterruptedIOException.
      Thread.sleep(1000);
      thread.interrupt();
      ctx.stop();

      //make sure the channels are still open
      assertTrue(source.isOpen());
      assertTrue(sink.isOpen());
View Full Code Here

  public void testNoErrors() throws Exception {
    final AtomicInteger threadsRun = new AtomicInteger();

    TestContext ctx = new TestContext();
    for (int i = 0; i < 3; i++) {
      ctx.addThread(new TestingThread(ctx) {
        @Override
        public void doWork() throws Exception {
          threadsRun.incrementAndGet();
        }
      });
View Full Code Here

  }

  @Test
  public void testThreadFails() throws Exception {
    TestContext ctx = new TestContext();
    ctx.addThread(new TestingThread(ctx) {
      @Override
      public void doWork() throws Exception {
        fail(FAIL_MSG);
      }
    });
View Full Code Here

  }

  @Test
  public void testThreadThrowsCheckedException() throws Exception {
    TestContext ctx = new TestContext();
    ctx.addThread(new TestingThread(ctx) {
      @Override
      public void doWork() throws Exception {
        throw new IOException("my ioe");
      }
    });
View Full Code Here

       * Verify that it handles interrupted threads properly.
       * Use a large timeout and expect the thread to return quickly
       * upon interruption.
       */
      ((SocketInputStream)in).setTimeout(0);
      TestingThread thread = new TestingThread(ctx) {
        @Override
        public void doWork() throws Exception {
          try {
            in.read();
            fail("Did not fail with interrupt");
          } catch (InterruptedIOException ste) {
            LOG.info("Got expection while reading as expected : " +
                ste.getMessage());
          }
        }
      };
      ctx.addThread(thread);
      ctx.startThreads();
      // If the thread is interrupted before it calls read()
      // then it throws ClosedByInterruptException due to
      // some Java quirk. Waiting for it to call read()
      // gets it into select(), so we get the expected
      // InterruptedIOException.
      Thread.sleep(1000);
      thread.interrupt();
      ctx.stop();

      //make sure the channels are still open
      assertTrue(source.isOpen());
      assertTrue(sink.isOpen());
View Full Code Here

  public void testNoErrors() throws Exception {
    final AtomicInteger threadsRun = new AtomicInteger();

    TestContext ctx = new TestContext();
    for (int i = 0; i < 3; i++) {
      ctx.addThread(new TestingThread(ctx) {
        @Override
        public void doWork() throws Exception {
          threadsRun.incrementAndGet();
        }
      });
View Full Code Here

  }

  @Test
  public void testThreadFails() throws Exception {
    TestContext ctx = new TestContext();
    ctx.addThread(new TestingThread(ctx) {
      @Override
      public void doWork() throws Exception {
        fail(FAIL_MSG);
      }
    });
View Full Code Here

  }

  @Test
  public void testThreadThrowsCheckedException() throws Exception {
    TestContext ctx = new TestContext();
    ctx.addThread(new TestingThread(ctx) {
      @Override
      public void doWork() throws Exception {
        throw new IOException("my ioe");
      }
    });
View Full Code Here

TOP

Related Classes of org.apache.hadoop.test.MultithreadedTestUtil.TestingThread

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.