@Test
  public void testRemove() {
    Assert.assertFalse(this.set.remove(this.k2));
    Assert.assertFalse(this.set.remove(this.keyE));

    addFromArray(this.set, this.key0, this.key1, this.key2, this.key3, this.key4);

    Assert.assertTrue(this.set.remove(this.k2));
    Assert.assertFalse(this.set.remove(this.k2));
    Assert.assertEquals(4, this.set.size());
    TestUtils.assertSortedListEquals(this.set.toArray(), 0, 1, 3, 4);
  }
  @Test
  public void listRequest() {
    JdbcContentPersistenceService tested = getTested();
    tested.LIST_PAGE_SIZE = 3;

    String sysContentType = "testtypelist";

    // case - no table exists for type
    {
      ListRequest req = tested.listRequestInit(sysContentType);
      Assert.assertFalse(req.hasContent());
    }

    // case - data handling test
    {

      // store in reverse order to see if listing uses correct ordering
      for (int i = 7; i >= 1; i--) addContent(tested, sysContentType, "aaa-" + i);

      ListRequest req = tested.listRequestInit(sysContentType);
      Assert.assertTrue(req.hasContent());
      Assert.assertNotNull(req.content());
      Assert.assertEquals(3, req.content().size());
      Assert.assertEquals("aaa-1", req.content().get(0).getId());
      // assert content is correctly loaded
      Assert.assertEquals(
          "aaa-1", req.content().get(0).getContent().get(ContentObjectFields.SYS_ID));
      Assert.assertEquals(
          "value aaa-1",
          req.content().get(0).getContent().get(ContentObjectFields.SYS_DESCRIPTION));
      // assert id only for others
      Assert.assertEquals("aaa-2", req.content().get(1).getId());
      Assert.assertEquals("aaa-3", req.content().get(2).getId());

      req = tested.listRequestNext(req);
      Assert.assertTrue(req.hasContent());
      Assert.assertNotNull(req.content());
      Assert.assertEquals(3, req.content().size());
      Assert.assertEquals("aaa-4", req.content().get(0).getId());
      Assert.assertEquals("aaa-5", req.content().get(1).getId());
      Assert.assertEquals("aaa-6", req.content().get(2).getId());

      req = tested.listRequestNext(req);
      Assert.assertTrue(req.hasContent());
      Assert.assertNotNull(req.content());
      Assert.assertEquals(1, req.content().size());
      Assert.assertEquals("aaa-7", req.content().get(0).getId());

      req = tested.listRequestNext(req);
      Assert.assertFalse(req.hasContent());
    }
  }
  @Test
  public void testIterable2() {
    addFromArray(this.set, this.keyE, this.key1, this.key2, this.key2, this.key3, this.key4);
    this.set.remove(this.k2);
    Assert.assertEquals(4, this.set.size());

    int counted = 0;
    for (final KTypeCursor<KType> cursor : this.set) {
      if (cursor.index == getKeys(this.set).length) {

        Assert.assertTrue(this.isAllocatedDefaultKey(this.set));
        TestUtils.assertEquals2(this.keyE, cursor.value);
        counted++;
        continue;
      }

      Assert.assertTrue(this.set.contains(cursor.value));
      TestUtils.assertEquals2(cursor.value, this.getKeys(this.set)[cursor.index]);
      counted++;
    }
    Assert.assertEquals(counted, this.set.size());

    this.set.clear();
    Assert.assertFalse(this.set.iterator().hasNext());
  }
  @Test
  public void testAdd() {
    Assert.assertTrue(this.set.add(this.key1));
    Assert.assertFalse(this.set.add(this.key1));
    Assert.assertEquals(1, this.set.size());

    Assert.assertTrue(this.set.add(this.keyE));
    Assert.assertFalse(this.set.add(this.keyE));

    Assert.assertEquals(2, this.set.size());

    Assert.assertTrue(this.set.add(this.key2));
    Assert.assertFalse(this.set.add(this.key2));

    Assert.assertEquals(3, this.set.size());
  }
Example #5
0
 public void assertFalse(boolean b) {
   try {
     Assert.assertFalse(b);
   } catch (Error e) {
     lastTestFailed = true;
     throw e;
   }
 }
  @Test
  public void simulateClusterTableCreation() {
    JdbcContentPersistenceService tested = getTested();

    Assert.assertFalse(tested.checkTableExists("table1"));
    createTable("TABLE1");
    Assert.assertTrue(tested.checkTableExists("table1"));
  }
 @Test
 public void testNullKey() {
   this.set.add((KType) null);
   Assert.assertEquals(1, this.set.size());
   Assert.assertTrue(this.set.contains(null));
   Assert.assertTrue(this.set.remove(null));
   Assert.assertEquals(0, this.set.size());
   Assert.assertFalse(this.set.contains(null));
 }
  @Test
  public void checkAndEnsureTableExists() {
    JdbcContentPersistenceService tested = getTested();

    Assert.assertFalse(tested.checkTableExists("table1"));
    Assert.assertFalse(tested.checkTableExists("table1"));

    tested.ensureTableExists("table1");
    Assert.assertTrue(tested.checkTableExists("table1"));

    tested.ensureTableExists("table1");
    Assert.assertTrue(tested.checkTableExists("table1"));
    Assert.assertTrue(tested.checkTableExists("table1"));

    Assert.assertFalse(tested.checkTableExists("table_2"));
    tested.ensureTableExists("table_2");
    Assert.assertTrue(tested.checkTableExists("table_2"));
    Assert.assertTrue(tested.checkTableExists("table1"));
  }
  @Test
  public void testAtomicCommitMissingFinal() {
    TaskAttemptContext taskAttemptContext = getTaskAttemptContext(config);
    JobContext jobContext =
        new JobContextImpl(
            taskAttemptContext.getConfiguration(),
            taskAttemptContext.getTaskAttemptID().getJobID());
    Configuration conf = jobContext.getConfiguration();

    String workPath = "/tmp1/" + String.valueOf(rand.nextLong());
    String finalPath = "/tmp1/" + String.valueOf(rand.nextLong());
    FileSystem fs = null;
    try {
      OutputCommitter committer = new CopyCommitter(null, taskAttemptContext);
      fs = FileSystem.get(conf);
      fs.mkdirs(new Path(workPath));

      conf.set(DistCpConstants.CONF_LABEL_TARGET_WORK_PATH, workPath);
      conf.set(DistCpConstants.CONF_LABEL_TARGET_FINAL_PATH, finalPath);
      conf.setBoolean(DistCpConstants.CONF_LABEL_ATOMIC_COPY, true);

      Assert.assertTrue(fs.exists(new Path(workPath)));
      Assert.assertFalse(fs.exists(new Path(finalPath)));
      committer.commitJob(jobContext);
      Assert.assertFalse(fs.exists(new Path(workPath)));
      Assert.assertTrue(fs.exists(new Path(finalPath)));

      // Test for idempotent commit
      committer.commitJob(jobContext);
      Assert.assertFalse(fs.exists(new Path(workPath)));
      Assert.assertTrue(fs.exists(new Path(finalPath)));

    } catch (IOException e) {
      LOG.error("Exception encountered while testing for preserve status", e);
      Assert.fail("Atomic commit failure");
    } finally {
      TestDistCpUtils.delete(fs, workPath);
      TestDistCpUtils.delete(fs, finalPath);
    }
  }
  @Test
  /*! #if ($TemplateOptions.KTypeGeneric) !*/
  @SuppressWarnings("unchecked")
  /*! #end !*/
  public void testEquals() {
    final KTypeSet<KType> l0 = getFrom();
    Assert.assertEquals(l0, createNewSetInstance());

    KTypeSet<KType> l1 = getFrom(this.k1, this.k2, this.k3, this.k4, this.k5);
    KTypeSet<KType> l2 = getFrom(this.k2, this.k1);

    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    Assert.assertFalse(l1.equals(null));
    Assert.assertFalse(l2.equals(null));

    l2.add(this.k5);
    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l2.add(this.k4);
    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l2.add(this.k3);
    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    l1.add(this.keyE);
    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l2.add(this.keyE);

    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    l2.remove(this.keyE);

    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l2.add(this.keyE);

    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    l2.remove(this.k7); // not present, sets are still OK
    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    l2.remove(this.k2);

    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l1.remove(this.k2);
    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    l1.add(this.k7);
    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l2.clear();
    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l1.clear();
    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    // Same size, different contents
    l1 = getFrom(this.k1, this.k2, this.k3, this.k4, this.k5);
    l2 = getFrom(this.k2, this.k1, this.key5, this.key6, this.key7);

    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);
  }