Пример #1
0
  public void testInverseOwnerOneToMany() {
    OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
    startTx(em);
    AnnoTest1 pc = new AnnoTest1(5);
    AnnoTest2 pc2 = new AnnoTest2(15, "foo");
    pc.getInverseOwnerOneMany().add(pc2);
    pc2.setOneManyOwner(pc);
    pc2 = new AnnoTest2(20, "foobar");
    pc.getInverseOwnerOneMany().add(pc2);
    pc2.setOneManyOwner(pc);
    em.persist(pc);
    em.persistAll(pc.getInverseOwnerOneMany());
    endTx(em);
    endEm(em);

    em = (OpenJPAEntityManager) currentEntityManager();
    pc = em.find(AnnoTest1.class, em.getObjectId(pc));
    Collection<AnnoTest2> many = pc.getInverseOwnerOneMany();
    assertEquals(2, many.size());
    for (AnnoTest2 pc3 : many) {
      assertEquals(pc, pc3.getOneManyOwner());
      switch ((int) pc3.getPk1()) {
        case 15:
          assertEquals("foo", pc3.getPk2());
          break;
        case 20:
          assertEquals("foobar", pc3.getPk2());
          break;
        default:
          fail("unknown element:" + pc3.getPk1());
      }
    }
    endEm(em);
  }
Пример #2
0
  /** Check if the getSubBuilders properly predicts the output. */
  public static void testSubBuilders() throws Exception {
    Workspace ws = Workspace.getWorkspace(new File("test/ws"));
    Project project = ws.getProject("p4-sub");

    Collection<? extends Builder> bs = project.getSubBuilders();
    assertNotNull(bs);
    assertEquals(3, bs.size());
    Set<String> names = new HashSet<String>();
    for (Builder b : bs) {
      names.add(b.getBsn());
    }
    assertTrue(names.contains("p4-sub.a"));
    assertTrue(names.contains("p4-sub.b"));
    assertTrue(names.contains("p4-sub.c"));

    File[] files = project.build();
    assertTrue(project.check());

    System.err.println(Processor.join(project.getErrors(), "\n"));
    System.err.println(Processor.join(project.getWarnings(), "\n"));
    assertEquals(0, project.getErrors().size());
    assertEquals(0, project.getWarnings().size());
    assertNotNull(files);
    assertEquals(3, files.length);
    for (File file : files) {
      Jar jar = new Jar(file);
      Manifest m = jar.getManifest();
      assertTrue(names.contains(m.getMainAttributes().getValue("Bundle-SymbolicName")));
    }
  }
Пример #3
0
  /**
   * The added suite will be always executed locally, but in parallel with other locally or remotely
   * running tests. This comes handy for tests that cannot be distributed for some environmental
   * reasons, but still would benefit from parallel execution.
   *
   * <p>Note, that local suites will be executed on local node even if grid topology only allows
   * remote nodes.
   *
   * @param localSuite Test to execute locally in parallel with other local or distributed tests.
   */
  @SuppressWarnings({"TypeMayBeWeakened"})
  public void addTest(GridJunit3LocalTestSuite localSuite) {
    if (!locTests.contains(localSuite.getName())) {
      locTests.add(localSuite.getName());
    }

    addTest((Test) localSuite);
  }
 /** Checks that sync has exactly the given queued threads. */
 void assertHasQueuedThreads(AbstractQueuedLongSynchronizer sync, Thread... expected) {
   Collection<Thread> actual = sync.getQueuedThreads();
   assertEquals(expected.length > 0, sync.hasQueuedThreads());
   assertEquals(expected.length, sync.getQueueLength());
   assertEquals(expected.length, actual.size());
   assertEquals(expected.length == 0, actual.isEmpty());
   assertEquals(new HashSet<Thread>(actual), new HashSet<Thread>(Arrays.asList(expected)));
 }
Пример #5
0
 private static Project testBuildAll(String dependsOn, int count) throws Exception {
   Workspace ws = new Workspace(new File("test/ws"));
   Project all = ws.getProject("build-all");
   all.setProperty("-dependson", dependsOn);
   all.prepare();
   Collection<Project> dependson = all.getDependson();
   assertEquals(count, dependson.size());
   return all;
 }
 /** values collection contains all values */
 public void testDescendingValues() {
   ConcurrentNavigableMap map = dmap5();
   Collection s = map.values();
   assertEquals(5, s.size());
   assertTrue(s.contains("A"));
   assertTrue(s.contains("B"));
   assertTrue(s.contains("C"));
   assertTrue(s.contains("D"));
   assertTrue(s.contains("E"));
 }
Пример #7
0
 /** Duplicates in runbundles gave a bad error, should be ignored */
 public static void testRunbundleDuplicates() throws Exception {
   Workspace ws = new Workspace(new File("test/ws"));
   Project top = ws.getProject("p1");
   top.clear();
   top.setProperty("-runbundles", "org.apache.felix.configadmin,org.apache.felix.configadmin");
   Collection<Container> runbundles = top.getRunbundles();
   assertTrue(top.check("Multiple bundles with the same final URL"));
   assertNotNull(runbundles);
   assertEquals(1, runbundles.size());
 }
Пример #8
0
 private static void assertEqualList(List<?> a, Collection<?> b) {
   if (a.size() == b.size()) {
     for (Object x : a) {
       if (!b.contains(x))
         throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">");
     }
     return;
   }
   throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">");
 }
Пример #9
0
 /** Test 2 equal bsns but diff. versions */
 public static void testSameBsnRunBundles() throws Exception {
   Workspace ws = new Workspace(new File("test/ws"));
   Project top = ws.getProject("p1");
   top.setProperty(
       "-runbundles",
       "org.apache.felix.configadmin;version='[1.0.1,1.0.1]',org.apache.felix.configadmin;version='[1.1.0,1.1.0]'");
   Collection<Container> runbundles = top.getRunbundles();
   assertTrue(top.check());
   assertNotNull(runbundles);
   assertEquals(2, runbundles.size());
 }
Пример #10
0
 /** Test bnd.bnd of project `foo`: `-runbundles: foo;version=latest` */
 public static void testRunBundlesContainsSelf() throws Exception {
   Workspace ws = new Workspace(new File("test/ws"));
   Project top = ws.getProject("p1");
   top.setProperty("-runbundles", "p1;version=latest");
   top.setChanged();
   top.isStale();
   Collection<Container> runbundles = top.getRunbundles();
   assertTrue(top.check("Circular dependency"));
   assertNotNull(runbundles);
   assertEquals(0, runbundles.size());
 }
 /** Values.toArray contains all values */
 public void testDescendingValuesToArray() {
   ConcurrentNavigableMap map = dmap5();
   Collection v = map.values();
   Object[] ar = v.toArray();
   ArrayList s = new ArrayList(Arrays.asList(ar));
   assertEquals(5, ar.length);
   assertTrue(s.contains("A"));
   assertTrue(s.contains("B"));
   assertTrue(s.contains("C"));
   assertTrue(s.contains("D"));
   assertTrue(s.contains("E"));
 }
Пример #12
0
  /**
   * Adds a test to be executed on the grid. In case of test suite, all tests inside of test suite
   * will be executed sequentially on some remote node.
   *
   * @param test Test to add.
   */
  @Override
  public void addTest(Test test) {
    if (copy == null) {
      copy = new TestSuite(getName());
    }

    // Add test to the list of local ones.
    if (test instanceof GridJunit3LocalTestSuite) {
      String testName = ((TestSuite) test).getName();

      if (!locTests.contains(testName)) {
        locTests.add(testName);
      }
    }

    if (test instanceof GridJunit3TestSuite) {
      copy.addTest(((GridJunit3TestSuite) test).copy);

      super.addTest(new GridJunit3TestSuiteProxy(((GridJunit3TestSuite) test).copy, factory));
    } else if (test instanceof GridJunit3TestSuiteProxy) {
      copy.addTest(((GridJunit3TestSuiteProxy) test).getOriginal());

      super.addTest(test);
    } else if (test instanceof GridJunit3TestCaseProxy) {
      copy.addTest(((GridJunit3TestCaseProxy) test).getGridGainJunit3OriginalTestCase());

      super.addTest(test);
    } else if (test instanceof TestSuite) {
      copy.addTest(test);

      super.addTest(new GridJunit3TestSuiteProxy((TestSuite) test, factory));
    } else {
      assert test instanceof TestCase
          : "Test must be either instance of TestSuite or TestCase: " + test;

      copy.addTest(test);

      super.addTest(factory.createProxy((TestCase) test));
    }
  }
  private void runMassiveFileTest(int maxpages) throws Exception {
    String text = "Testing, 1, 2, 3: ";
    String name = NAME1;
    Benchmark mark = new Benchmark();

    System.out.println("Building a massive repository of " + maxpages + " pages...");

    mark.start();
    for (int i = 0; i < maxpages; i++) {
      engine.saveText(name + i, text + i);
    }
    mark.stop();

    System.out.println("Total time to save " + maxpages + " pages was " + mark.toString());
    System.out.println("Saved " + mark.toString(maxpages) + " pages/second");

    mark.reset();

    mark.start();
    Collection pages = engine.getPageManager().getAllPages();
    mark.stop();

    System.out.println("Got a list of all pages in " + mark);

    mark.reset();
    mark.start();

    for (Iterator i = pages.iterator(); i.hasNext(); ) {
      String foo = engine.getPureText((WikiPage) i.next());

      assertNotNull(foo);
    }
    mark.stop();

    System.out.println("Read through all of the pages in " + mark);
    System.out.println("which is " + mark.toString(maxpages) + " pages/second");
  }
Пример #14
0
  /**
   * Runs all tests belonging to this test suite on the grid.
   *
   * @param result Test result collector.
   */
  @Override
  public void run(TestResult result) {
    if (isDisabled) {
      copy.run(result);
    } else {
      GridTestRouter router = createRouter();

      Grid grid = startGrid();

      try {
        List<GridTaskFuture<?>> futs = new ArrayList<GridTaskFuture<?>>(testCount());

        List<GridJunit3SerializableTest> tests =
            new ArrayList<GridJunit3SerializableTest>(testCount());

        for (int i = 0; i < testCount(); i++) {
          Test junit = testAt(i);

          GridJunit3SerializableTest test;

          if (junit instanceof TestSuite) {
            test = new GridJunit3SerializableTestSuite((TestSuite) junit);
          } else {
            assert junit instanceof TestCase
                : "Test must be either TestSuite or TestCase: " + junit;

            test = new GridJunit3SerializableTestCase((TestCase) junit);
          }

          tests.add(test);

          if (clsLdr == null) {
            clsLdr = U.detectClassLoader(junit.getClass());
          }

          futs.add(
              grid.execute(
                  new GridJunit3Task(junit.getClass(), clsLdr),
                  new GridJunit3Argument(router, test, locTests.contains(test.getName())),
                  timeout));
        }

        for (int i = 0; i < testCount(); i++) {
          GridTaskFuture<?> fut = futs.get(i);

          GridJunit3SerializableTest origTest = tests.get(i);

          try {
            GridJunit3SerializableTest resTest = (GridJunit3SerializableTest) fut.get();

            origTest.setResult(resTest);

            origTest.getTest().run(result);
          } catch (GridException e) {
            handleFail(result, origTest, e);
          }
        }
      } finally {
        stopGrid();
      }
    }
  }