Exemplo n.º 1
0
 public void run() {
   try {
     Thread.sleep(MEDIUM_DELAY_MS);
   } catch (Exception e) {
     fail("Unexpected exception");
   }
 }
Exemplo n.º 2
0
 public void run() {
   try {
     Thread.sleep(LONG_DELAY_MS);
     done = true;
   } catch (Exception e) {
   }
 }
Exemplo n.º 3
0
 public void run() {
   try {
     Thread.sleep(MEDIUM_DELAY_MS);
     fail("should throw exception");
   } catch (InterruptedException success) {
   }
 }
 /**
  * The AIM server doesn't like it if we change states too often and we use this method to slow
  * things down.
  */
 private void pauseBetweenStateChanges() {
   try {
     Thread.sleep(5000);
   } catch (InterruptedException ex) {
     logger.debug("Pausing between state changes was interrupted", ex);
   }
 }
Exemplo n.º 5
0
  /*
   * Launches against the agent& main
   */
  public void testAgentAndMain() throws Exception {
    Project project = workspace.getProject("p1");
    Run bndrun = new Run(workspace, project.getBase(), project.getFile("one.bndrun"));
    bndrun.setProperty("-runpath", "biz.aQute.remote.launcher");
    bndrun.setProperty("-runbundles", "bsn-1,bsn-2");
    bndrun.setProperty("-runremote", "agent,main;agent=1090");

    final RemoteProjectLauncherPlugin pl =
        (RemoteProjectLauncherPlugin) bndrun.getProjectLauncher();
    pl.prepare();

    List<? extends RunSession> sessions = pl.getRunSessions();
    assertEquals(2, sessions.size());

    RunSession agent = sessions.get(0);
    RunSession main = sessions.get(1);

    CountDownLatch agentLatch = launch(agent);
    CountDownLatch mainLatch = launch(main);

    agent.waitTillStarted(1000);
    main.waitTillStarted(1000);
    Thread.sleep(500);

    agent.cancel();
    main.cancel();

    agentLatch.await();
    mainLatch.await();
    assertEquals(-3, agent.getExitCode());
    assertEquals(-3, main.getExitCode());

    bndrun.close();
  }
Exemplo n.º 6
0
  @SuppressWarnings("deprecation")
  // test explicitly needs to use "stop", which is deprecated
  public static void testCase() {
    Thread t =
        new Thread(
            new Runnable() {
              public void run() {
                try {
                  synchronized (o) {
                    in_wait = true;
                    // System.out.println("wait");
                    o.wait(3000); // just a bit
                    in_wait = false;
                  }
                } catch (Exception e) {
                  // System.out.println(Thread.currentThread().getName() + " caught " + e);
                  // e.printStackTrace();
                  in_wait = false;
                }
              }
            });

    t.start();
    while (!in_wait) {} // Lame
    synchronized (o) {
      // System.out.println("stop");
      t.stop();
    }
    try {
      Thread.sleep(8000); // sleep longer than our wait thread
    } catch (Exception e) {
      assertTrue(false);
    }
    assertTrue(in_wait); // if we finished wait, we failed to interrupt
  }
  public void testEmptyHeader() {
    fFrame = new JFrame("Test Window");

    // Create a panel to hold all other components
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());

    // Create a new table instance
    MyTableModel myModel = new MyTableModel();
    fTable = new JTable(myModel);

    // Add the table to a scrolling pane
    JScrollPane scrollPane = new JScrollPane(fTable);
    topPanel.add(scrollPane, BorderLayout.CENTER);

    fFrame.getContentPane().setLayout(new BorderLayout());
    fFrame.getContentPane().add(BorderLayout.CENTER, topPanel);

    fFrame.setSize(400, 450);
    fFrame.setLocation(20, 20);
    fFrame.setVisible(true);
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    JTableHeader header = fTable.getTableHeader();
    assertTrue(
        "JTableHeader greater than 5 pixels tall with empty string first element.",
        header.getSize().height > 5);
    fFrame.setVisible(false);
    fFrame.dispose();
  }
 public boolean checkEvents(BundleEvent[] expevents) {
   boolean res = true;
   for (int i = 0; i < 20; i++) {
     try {
       Thread.sleep(100);
     } catch (InterruptedException ignore) {
     }
     if (events.size() == expevents.length) {
       break;
     }
   }
   if (events.size() == expevents.length) {
     for (int i = 0; i < events.size(); i++) {
       BundleEvent be = (BundleEvent) events.elementAt(i);
       if (!(be.getBundle().equals(expevents[i].getBundle())
           && be.getType() == expevents[i].getType())) {
         res = false;
       }
     }
   } else {
     res = false;
   }
   if (!res) {
     out.println("Real events");
     for (int i = 0; i < events.size(); i++) {
       BundleEvent be = (BundleEvent) events.elementAt(i);
       out.println("Event " + be.getBundle() + ", Type " + be.getType());
     }
     out.println("Expected events");
     for (int i = 0; i < expevents.length; i++) {
       out.println("Event " + expevents[i].getBundle() + ", Type " + expevents[i].getType());
     }
   }
   return res;
 }
Exemplo n.º 9
0
 public Object call() {
   try {
     Thread.sleep(SMALL_DELAY_MS);
   } catch (Exception e) {
     fail("Unexpected exception");
   }
   return Boolean.TRUE;
 }
Exemplo n.º 10
0
 public Object call() {
   try {
     Thread.sleep(SMALL_DELAY_MS);
     done = true;
   } catch (Exception e) {
   }
   return Boolean.TRUE;
 }
 public void run() {
   Configuration conf = new Configuration();
   try {
     conf.setEventManager(new EventManager());
     Thread.sleep(100);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
 public void run() {
   Configuration conf = new Configuration();
   try {
     conf.setBulkFitnessFunction(new TestBulkFitnessFunction());
     Thread.sleep(100);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
 public void testStopsWhenQueryBetterThanElapsed() throws Exception {
   System.gc();
   BestQueryExplainer bq = new BestQueryExplainer();
   bq.add(q1); // Takes 600 milliseconds
   Thread.sleep(700);
   try {
     bq.add(q2);
     fail("Expected: BestQueryException");
   } catch (BestQueryException e) {
   }
 }
Exemplo n.º 14
0
 /**
  * Delays, via Thread.sleep, for the given millisecond delay, but if the sleep is shorter than
  * specified, may re-sleep or yield until time elapses.
  */
 static void delay(long millis) throws InterruptedException {
   long startTime = System.nanoTime();
   long ns = millis * 1000 * 1000;
   for (; ; ) {
     if (millis > 0L) Thread.sleep(millis);
     else // too short to sleep
     Thread.yield();
     long d = ns - (System.nanoTime() - startTime);
     if (d > 0L) millis = d / (1000 * 1000);
     else break;
   }
 }
Exemplo n.º 15
0
  /*
   * Launches against the agent
   */
  public void testSimpleLauncher() throws Exception {
    Project project = workspace.getProject("p1");
    Run bndrun = new Run(workspace, project.getBase(), project.getFile("one.bndrun"));
    bndrun.setProperty("-runpath", "biz.aQute.remote.launcher");
    bndrun.setProperty("-runbundles", "bsn-1,bsn-2");
    bndrun.setProperty("-runremote", "test");

    final RemoteProjectLauncherPlugin pl =
        (RemoteProjectLauncherPlugin) bndrun.getProjectLauncher();
    pl.prepare();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger exitCode = new AtomicInteger(-1);

    List<? extends RunSession> sessions = pl.getRunSessions();
    assertEquals(1, sessions.size());

    final RunSession session = sessions.get(0);

    Thread t =
        new Thread("test-launch") {
          public void run() {
            try {
              exitCode.set(session.launch());
            } catch (Exception e) {
              e.printStackTrace();
            } finally {
              latch.countDown();
            }
          }
        };
    t.start();
    Thread.sleep(500);

    for (Bundle b : context.getBundles()) {
      System.out.println(b.getLocation());
    }
    assertEquals(4, context.getBundles().length);
    String p1 = t1.getAbsolutePath();
    System.out.println(p1);

    assertNotNull(context.getBundle(p1));
    assertNotNull(context.getBundle(t2.getAbsolutePath()));

    pl.cancel();
    latch.await();

    assertEquals(-3, exitCode.get());

    bndrun.close();
  }
Exemplo n.º 16
0
  // [myakovlev] Do not delete - it is for debugging
  public static void tryGc(int times) {
    if ((ourMode & RUN_GC) == 0) return;

    for (int qqq = 1; qqq < times; qqq++) {
      try {
        Thread.sleep(qqq * 1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      System.gc();
      // long mem = Runtime.getRuntime().totalMemory();
      log("Runtime.getRuntime().totalMemory() = " + Runtime.getRuntime().totalMemory());
    }
  }
Exemplo n.º 17
0
  public void testRepeatedSearch() throws Exception {
    final int searchInterval = 3000;
    Search search = new Search(SearchTest.URL, "xxx");

    ResultsListener listener =
        new ResultsListener() {
          public void executed(Search search) {
            ++actualResultsCount;
          }
        };

    SearchScheduler scheduler = new SearchScheduler(listener);
    scheduler.repeat(search, searchInterval);

    final int expectedResultsCount = 3;
    Thread.sleep((expectedResultsCount - 1) * searchInterval + 1000);

    scheduler.stop();
    assertEquals(expectedResultsCount, actualResultsCount);
  }
Exemplo n.º 18
0
  public static void testOutofDate() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("test/ws"));
    Project project = ws.getProject("p3");
    File bnd = new File("test/ws/p3/bnd.bnd");
    assertTrue(bnd.exists());

    project.clean();
    File pt = project.getTarget();
    if (!pt.exists() && !pt.mkdirs()) {
      throw new IOException("Could not create directory " + pt);
    }
    try {
      // Now we build it.
      File[] files = project.build();
      System.err.println(project.getErrors());
      System.err.println(project.getWarnings());
      assertTrue(project.isOk());
      assertNotNull(files);
      assertEquals(1, files.length);

      // Now we should not rebuild it
      long lastTime = files[0].lastModified();
      files = project.build();
      assertEquals(1, files.length);
      assertTrue(files[0].lastModified() == lastTime);

      Thread.sleep(2000);

      project.updateModified(System.currentTimeMillis(), "Testing");
      files = project.build();
      assertEquals(1, files.length);
      assertTrue("Must have newer files now", files[0].lastModified() > lastTime);
    } finally {
      project.clean();
    }
  }
Exemplo n.º 19
0
 public void run() {
   try {
     Thread.sleep(LONG_DELAY_MS);
   } catch (InterruptedException success) {
   }
 }
  protected void setUp() throws IOException, InterruptedException {
    JGN.register(MyCertifiedMessage.class);
    JGN.register(MyRealtimeMessage.class);
    JGN.register(MyUniqueMessage.class);
    JGN.register(MySerializableMessage.class);

    // Create first MessageServer
    serverAddress1 = new InetSocketAddress(InetAddress.getLocalHost(), 1000);
    if (tcp) {
      server1 = new TCPMessageServer(serverAddress1);
    } else {
      server1 = new UDPMessageServer(serverAddress1);
    }
    if (debug) {
      server1.addMessageListener(new DebugListener("Server1"));
      server1.addConnectionListener(new DebugListener("Server1"));
    }
    server1.addConnectionListener(
        new ConnectionListener() {
          public void connected(MessageClient client) {
            client1Disconnected = false;
          }

          public void negotiationComplete(MessageClient client) {
            client1to2 = client;
          }

          public void disconnected(MessageClient client) {
            System.out.println("Disconnected1");
            client1Disconnected = true;
          }

          public void kicked(MessageClient client, String reason) {}
        });
    JGN.createThread(server1).start();

    // Create second MessageServer
    serverAddress2 = new InetSocketAddress(InetAddress.getLocalHost(), 2000);
    if (tcp) {
      server2 = new TCPMessageServer(serverAddress2);
    } else {
      server2 = new UDPMessageServer(serverAddress2);
    }
    if (debug) {
      server2.addMessageListener(new DebugListener("Server2"));
      server2.addConnectionListener(new DebugListener("Server1"));
    }
    server2.addConnectionListener(
        new ConnectionListener() {
          public void connected(MessageClient client) {
            client2Disconnected = false;
          }

          public void negotiationComplete(MessageClient client) {
            client2to1 = client;
          }

          public void disconnected(MessageClient client) {
            System.out.println("Disconnected2");
            client2Disconnected = true;
          }

          public void kicked(MessageClient client, String reason) {}
        });
    JGN.createThread(server2).start();

    // Connect server2 to server1
    MessageClient client = server2.connectAndWait(serverAddress1, 5000);
    if (client == null) {
      System.err.println("Unable to establish connection!");
    } else {
      System.out.println("Connection established successfully");
    }
    long time = System.currentTimeMillis();
    while (System.currentTimeMillis() < time + 5000) {
      if ((client1to2 != null) && (client2to1 != null)) break;
      Thread.sleep(1);
    }
    assertTrue(client1to2 != null);
    assertTrue(client2to1 != null);
  }
Exemplo n.º 21
0
 public void run() {
   try {
     Thread.sleep(SMALL_DELAY_MS);
   } catch (Exception e) {
   }
 }
  public void testDrawLinesAWT() throws Exception {

    Frame dummy = new Frame();
    Window[] windows = new Window[3];
    Waypoint[] painted = new Waypoint[windows.length];

    for (int i = 0; i < 3; i++) {

      painted[i] =
          new Waypoint(); // this gets cleared in the paint method of the TestWindow, so we know
      // that at least on paint() call has been made

      // create the test windows
      switch (i) {
        case 0:
          windows[i] = new TestWindow(dummy, painted[i], RenderingHints.VALUE_ANTIALIAS_ON);
          break;
        case 1:
          windows[i] = new TestWindow(dummy, painted[i], RenderingHints.VALUE_ANTIALIAS_OFF);
          break;
        case 2:
          windows[i] = new TestWindow(dummy, painted[i], RenderingHints.VALUE_ANTIALIAS_DEFAULT);
          break;
        default:
          throw new Exception("Should not get here!");
      }

      windows[i].setBounds(50 + (i * (kWidth + 5)), 50, kWidth, KHeight);
      // VisibilityValidator checkpoint = new VisibilityValidator(windows[i]); // Re-add this when
      // VisiblityValidator handes windows (currently only handles frames)
      windows[i].setVisible(true);

      // checkpoint.requireVisible();
      // assertTrue( "Could not confirm test window was visible", checkpoint.isValid() );

      Thread.sleep(kPaintTimeOut);

      painted[i].requireClear();
      assertTrue(
          "paint() not called on test window after " + kPaintTimeOut + "ms", painted[i].isClear());

      // dumpRedsFromImage(w);	// <-- turn this on for debugging info

      for (int ii = 0; ii < kProbePoints.length; ii++) {

        // Collect the colors of points just off the test line
        Point screen_offset = windows[i].getLocationOnScreen();
        int x = screen_offset.x + kProbePoints[ii].x;
        int y = screen_offset.y + kProbePoints[ii].y;
        Color fProbeColor = kRobot.getPixelColor(x, y);

        assertNotNull(fProbeColor);
        switch (i) {
            // RenderingHints.VALUE_ANTIALIAS_ON
          case 0:
            assertTrue(
                "Point just off line with ANTIALIAS_ON should not be white",
                Color.white.equals(fProbeColor) == false);
            break;

            // RenderingHints.VALUE_ANTIALIAS_OFF
          case 1:
            assertEquals(
                "Point just off line with ANTIALIAS_OFF should be white", Color.white, fProbeColor);
            break;

            // RenderingHints.VALUE_ANTIALIAS_DEFAULT
          case 2:
            assertEquals(
                "For non-Aqua, point just off line with VALUE_ANTIALIAS_DEFAULT should be white",
                Color.white,
                fProbeColor);
            break;
          default:
            throw new Exception("Should not get here!");
        }
      }
    }

    // make sure the window is up and drawn once
    Thread.sleep(100); // <-- do asserts here

    for (int i = 0; i < 3; i++) {
      windows[i].dispose();
    }

    dummy.dispose();
  }