Package org.jclouds.lifecycle

Examples of org.jclouds.lifecycle.Closer


   @Test
   public void testShutdownOnClose() throws IOException {
      Injector i = Guice.createInjector();

      Closer closer = i.getInstance(Closer.class);
      ListeningScheduledExecutorService executor = createMock(ListeningScheduledExecutorService.class);
      ExecutorServiceModule.shutdownOnClose(executor, closer);

      expect(executor.shutdownNow()).andReturn(ImmutableList.<Runnable> of()).atLeastOnce();

      replay(executor);
      closer.close();

      verify(executor);
   }
View Full Code Here


   @Test
   public void testShutdownOnClose() throws IOException {
      Injector i = Guice.createInjector();

      Closer closer = i.getInstance(Closer.class);
      ListeningExecutorService executor = createMock(ListeningExecutorService.class);
      ExecutorServiceModule.shutdownOnClose(executor, closer);

      expect(executor.shutdownNow()).andReturn(ImmutableList.<Runnable> of()).atLeastOnce();

      replay(executor);
      closer.close();

      verify(executor);
   }
View Full Code Here

               scheduledExecutor.shutdownNow();
         }
      };

      binder().requestInjection(executorCloser);
      Closer closer = new Closer();
      closer.addToClose(executorCloser);
      bind(Closer.class).toInstance(closer);

      ExecutionList list = new ExecutionList();
      bindPostInjectionInvoke(closer, list);
      bind(ExecutionList.class).toInstance(list);
View Full Code Here

               scheduledExecutor.shutdownNow();
         }
      };

      binder().requestInjection(executorCloser);
      Closer closer = new Closer();
      closer.addToClose(executorCloser);
      bind(Closer.class).toInstance(closer);

      ExecutionList list = new ExecutionList();
      bindPostInjectionInvoke(closer, list);
      bind(ExecutionList.class).toInstance(list);
View Full Code Here

   @Test
   public void testShutdownOnClose() throws IOException {
      Injector i = Guice.createInjector();

      Closer closer = i.getInstance(Closer.class);
      ListeningScheduledExecutorService executor = createMock(ListeningScheduledExecutorService.class);
      ExecutorServiceModule.shutdownOnClose(executor, closer);

      expect(executor.shutdownNow()).andReturn(ImmutableList.<Runnable> of()).atLeastOnce();

      replay(executor);
      closer.close();

      verify(executor);
   }
View Full Code Here

   @Test
   public void testShutdownOnClose() throws IOException {
      Injector i = Guice.createInjector();

      Closer closer = i.getInstance(Closer.class);
      ListeningExecutorService executor = createMock(ListeningExecutorService.class);
      ExecutorServiceModule.shutdownOnClose(executor, closer);

      expect(executor.shutdownNow()).andReturn(ImmutableList.<Runnable> of()).atLeastOnce();

      replay(executor);
      closer.close();

      verify(executor);
   }
View Full Code Here

   void testCloserClosesExecutor() throws IOException {
      Injector i = createInjector();
      ListeningExecutorService executor = i.getInstance(Key.get(ListeningExecutorService.class,
            named(PROPERTY_USER_THREADS)));
      assert !executor.isShutdown();
      Closer closer = i.getInstance(Closer.class);
      assert closer.getState() == Closer.State.AVAILABLE;
      closer.close();
      assert executor.isShutdown();
      assert closer.getState() == Closer.State.DONE;
   }
View Full Code Here

   void testCloserPreDestroyOrder() throws IOException {
      Injector i = createInjector();
      ListeningExecutorService userExecutor = i.getInstance(Key.get(ListeningExecutorService.class,
            named(PROPERTY_USER_THREADS)));
      assert !userExecutor.isShutdown();
      Closer closer = i.getInstance(Closer.class);
      assert closer.getState() == Closer.State.AVAILABLE;
      closer.close();
      assert userExecutor.isShutdown();
      assert closer.getState() == Closer.State.DONE;
   }
View Full Code Here

   }

   @Test
   void testCloserClosingState() throws InterruptedException {
      Injector i = createInjector();
      final Closer closer = i.getInstance(Closer.class);

      final CountDownLatch closeDone = new CountDownLatch(1);
      final CountDownLatch closeStart = new CountDownLatch(1);

      closer.addToClose(new Closeable() {
         @Override
         public void close() throws IOException {
             try {
                 closeStart.countDown();
                 assert closer.getState() == Closer.State.PROCESSING;
                 closeDone.await();
             } catch (InterruptedException e) {
                 assert false : e.getMessage();
             }
         }
      });

      Thread thread = new Thread(new Runnable() {
         @Override
         public void run() {
            try {
               closer.close();
            } catch (IOException e) {
               assert false : e.getMessage();
            }
         }
      });

      thread.start();

      closeStart.await();

      assert closer.getState() == Closer.State.PROCESSING;

      closeDone.countDown();

      thread.join();

      assert closer.getState() == Closer.State.DONE;
   }
View Full Code Here

   }

   @Test
   void testCloserCallOneClose() throws IOException, InterruptedException {
      Injector i = createInjector();
      final Closer closer = i.getInstance(Closer.class);

      Closeable closeable = createStrictMock(Closeable.class);

      closeable.close();

      expectLastCall();

      replay(closeable);

      closer.addToClose(closeable);

      Runnable closeContext = new Runnable() {
         @Override
         public void run() {
            try {
               closer.close();
            } catch (IOException e) {
               assert false : e.getMessage();
            }
         }
      };

      Thread thread1 = new Thread(closeContext);
      Thread thread2 = new Thread(closeContext);

      thread1.start();
      thread2.start();

      thread1.join();
      thread2.join();

      verify(closeable);

      assert closer.getState() == Closer.State.DONE;
   }
View Full Code Here

TOP

Related Classes of org.jclouds.lifecycle.Closer

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.