private void withCache(final Procedure4<ClientSlotCache> procedure) {
   ClientSlotCache clientSlotCache = null;
   try {
     clientSlotCache =
         (ClientSlotCache) Reflection4.getFieldValue(container(), "_clientSlotCache");
   } catch (ReflectException e) {
     Assert.fail("Can't get field _clientSlotCache on  container. " + e.toString());
   }
   procedure.apply(clientSlotCache);
 }
  @Test
  public void testDeleteMissing() {
    TaskAttemptContext taskAttemptContext = getTaskAttemptContext(config);
    JobContext jobContext =
        new JobContextImpl(
            taskAttemptContext.getConfiguration(),
            taskAttemptContext.getTaskAttemptID().getJobID());
    Configuration conf = jobContext.getConfiguration();

    String sourceBase;
    String targetBase;
    FileSystem fs = null;
    try {
      OutputCommitter committer = new CopyCommitter(null, taskAttemptContext);
      fs = FileSystem.get(conf);
      sourceBase = TestDistCpUtils.createTestSetup(fs, FsPermission.getDefault());
      targetBase = TestDistCpUtils.createTestSetup(fs, FsPermission.getDefault());
      String targetBaseAdd = TestDistCpUtils.createTestSetup(fs, FsPermission.getDefault());
      fs.rename(new Path(targetBaseAdd), new Path(targetBase));

      DistCpOptions options =
          new DistCpOptions(Arrays.asList(new Path(sourceBase)), new Path("/out"));
      options.setSyncFolder(true);
      options.setDeleteMissing(true);
      options.appendToConf(conf);

      CopyListing listing = new GlobbedCopyListing(conf, CREDENTIALS);
      Path listingFile = new Path("/tmp1/" + String.valueOf(rand.nextLong()));
      listing.buildListing(listingFile, options);

      conf.set(DistCpConstants.CONF_LABEL_TARGET_WORK_PATH, targetBase);
      conf.set(DistCpConstants.CONF_LABEL_TARGET_FINAL_PATH, targetBase);

      committer.commitJob(jobContext);
      if (!TestDistCpUtils.checkIfFoldersAreInSync(fs, targetBase, sourceBase)) {
        Assert.fail("Source and target folders are not in sync");
      }
      if (!TestDistCpUtils.checkIfFoldersAreInSync(fs, sourceBase, targetBase)) {
        Assert.fail("Source and target folders are not in sync");
      }

      // Test for idempotent commit
      committer.commitJob(jobContext);
      if (!TestDistCpUtils.checkIfFoldersAreInSync(fs, targetBase, sourceBase)) {
        Assert.fail("Source and target folders are not in sync");
      }
      if (!TestDistCpUtils.checkIfFoldersAreInSync(fs, sourceBase, targetBase)) {
        Assert.fail("Source and target folders are not in sync");
      }
    } catch (Throwable e) {
      LOG.error("Exception encountered while testing for delete missing", e);
      Assert.fail("Delete missing failure");
    } finally {
      TestDistCpUtils.delete(fs, "/tmp1");
      conf.set(DistCpConstants.CONF_LABEL_DELETE_MISSING, "false");
    }
  }
 @Test
 public void testNullInputStream() {
   try {
     new CompactMagicEnvelopeDeserializer().deserialize(null);
     Assert.fail("Should have received an IllegalArgumentException");
   } catch (IllegalArgumentException iae) {
     Assert.assertEquals("Cannot deserialize from null input stream.", iae.getMessage());
   } catch (Exception e) {
     Assert.fail("Expecting an IllegalArgumentException not a " + e.getClass().getName());
   }
 }
 @After
 public void cleanupMetaFolder() {
   Path meta = new Path("/meta");
   try {
     if (cluster.getFileSystem().exists(meta)) {
       cluster.getFileSystem().delete(meta, true);
       Assert.fail("Expected meta folder to be deleted");
     }
   } catch (IOException e) {
     LOG.error("Exception encountered while cleaning up folder", e);
     Assert.fail("Unable to clean up meta folder");
   }
 }
  @Test
  public void testPreserveStatus() {
    TaskAttemptContext taskAttemptContext = getTaskAttemptContext(config);
    JobContext jobContext =
        new JobContextImpl(
            taskAttemptContext.getConfiguration(),
            taskAttemptContext.getTaskAttemptID().getJobID());
    Configuration conf = jobContext.getConfiguration();

    String sourceBase;
    String targetBase;
    FileSystem fs = null;
    try {
      OutputCommitter committer = new CopyCommitter(null, taskAttemptContext);
      fs = FileSystem.get(conf);
      FsPermission sourcePerm = new FsPermission((short) 511);
      FsPermission initialPerm = new FsPermission((short) 448);
      sourceBase = TestDistCpUtils.createTestSetup(fs, sourcePerm);
      targetBase = TestDistCpUtils.createTestSetup(fs, initialPerm);

      DistCpOptions options =
          new DistCpOptions(Arrays.asList(new Path(sourceBase)), new Path("/out"));
      options.preserve(FileAttribute.PERMISSION);
      options.appendToConf(conf);

      CopyListing listing = new GlobbedCopyListing(conf, CREDENTIALS);
      Path listingFile = new Path("/tmp1/" + String.valueOf(rand.nextLong()));
      listing.buildListing(listingFile, options);

      conf.set(DistCpConstants.CONF_LABEL_TARGET_WORK_PATH, targetBase);

      committer.commitJob(jobContext);
      if (!checkDirectoryPermissions(fs, targetBase, sourcePerm)) {
        Assert.fail("Permission don't match");
      }

      // Test for idempotent commit
      committer.commitJob(jobContext);
      if (!checkDirectoryPermissions(fs, targetBase, sourcePerm)) {
        Assert.fail("Permission don't match");
      }

    } catch (IOException e) {
      LOG.error("Exception encountered while testing for preserve status", e);
      Assert.fail("Preserve status failure");
    } finally {
      TestDistCpUtils.delete(fs, "/tmp1");
    }
  }
  /**
   * Run an import export test with a specific test number.
   *
   * @param testNumber
   */
  private void runComparison(int testNumber) {
    currentTestName = getTestFileBaseName() + Integer.toString(testNumber);

    // copy the expected output into the input directory. this is the file we will
    // compare the output of the tests to
    String testXMLOutputFileName =
        generatedXML + getTestFileBaseName() + "ModifyOutput" + Integer.toString(testNumber);
    File outputXMLFile = new File(testXMLOutputFileName + ".xml");

    if (outputXMLFile == null) {
      Assert.fail("Output File: " + outputXMLFile + " not found!");
    }

    // copy the expected output into the input directory (the input of what will be compared for the
    // tests)
    // name it the current test name to make for uniform naming
    writeFileToInput(outputXMLFile, currentTestName);

    // find test xml file to load as input
    String testXMLInputFileName =
        generatedXML + getTestFileBaseName() + "ModifyInput" + Integer.toString(testNumber);
    File inputXMLFile = new File(testXMLInputFileName + ".xml");

    if (inputXMLFile == null) {
      Assert.fail("Input File: " + testXMLInputFileName + " not found!");
    }

    // get object to test
    Object jaxbObject = getObjectFromFile(inputXMLFile);

    // convert from jaxb to jmatter
    Object jmatterObject = jaxbToJmatter(jaxbObject);

    if (jmatterObject == null) {
      Assert.fail("Input File: " + testXMLInputFileName + " JAXB to jmatter conversion failed");
    }

    // convert back to jaxb object
    Object convertedJaxbObject = jmatterToJaxb(jmatterObject);

    if (convertedJaxbObject == null) {
      Assert.fail("Input File: " + testXMLInputFileName + " jmatter JAXB conversion failed");
    }

    writeObjectToOutput(currentTestName, convertedJaxbObject);

    xmlUnitTest(currentTestName);
  }
  private void assertTableContent(
      final JdbcContentPersistenceService tested,
      final String sysContentType,
      final String id,
      final Date expectedUpdated) {
    final String tablename = tested.getTableName(sysContentType);

    try (final Connection conn = this.getTested().searchiskoDs.getConnection();
        final PreparedStatement statement =
            conn.prepareStatement(
                String.format(
                    "select sys_content_type, updated from %s where id = ?", tablename))) {
      statement.setString(1, id);
      try (final ResultSet rs = statement.executeQuery()) {
        Assert.assertTrue(rs.next());
        Assert.assertEquals(sysContentType, rs.getString(1));
        Timestamp actualTimestamp = rs.getTimestamp(2);
        if (expectedUpdated != null) {
          Assert.assertEquals(new Timestamp(expectedUpdated.getTime()), actualTimestamp);
        } else {
          Assert.assertNotNull(actualTimestamp);
        }
      }
    } catch (SQLException e) {
      Assert.fail(e.getMessage());
    }
  }
  @BeforeClass
  public static void MyTestFixtureSetUp() {
    StringBuffer sbf = new StringBuffer();

    sbf.append("<root>\n");
    sbf.append("\t<level1>\n");
    sbf.append("\t<value>Wert 1</value>\n");
    sbf.append("\t<value>Wert 2</value>\n");
    sbf.append("\t<value>Wert 3</value>\n");
    sbf.append("\t</level1>\n");
    sbf.append("</root>\n");

    try {
      BufferedWriter bwr = new BufferedWriter(new FileWriter(new File("OKW_XmlReaderTestXML.xml")));

      // write contents of StringBuffer to a file
      bwr.write(sbf.toString());

      // flush the stream
      bwr.flush();

      // close the stream
      bwr.close();
    } catch (IOException e) {
      Assert.fail(e.getMessage());
    }
  }
  @Test
  public void createFixedLengthStringTlv() throws Exception {
    Tlv tlv0 = null;

    tlv0 = TlvUtil.createFixedLengthStringTlv((short) 0x0001, null, 2, "ISO-8859-1");
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("0000"), tlv0.getValue());

    tlv0 = TlvUtil.createFixedLengthStringTlv((short) 0x0001, "", 2);
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("0000"), tlv0.getValue());

    tlv0 = TlvUtil.createFixedLengthStringTlv((short) 0x0001, "1", 2, "ISO-8859-1");
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("3100"), tlv0.getValue());

    tlv0 = TlvUtil.createFixedLengthStringTlv((short) 0x0001, "12", 2);
    Assert.assertEquals((short) 0x0001, tlv0.getTag());
    Assert.assertArrayEquals(HexUtil.toByteArray("3132"), tlv0.getValue());

    try {
      tlv0 = TlvUtil.createFixedLengthStringTlv((short) 0x0001, "12", 1, "ISO-8859-1");
      Assert.fail();
    } catch (TlvConvertException e) {
      // correct behavior
    }
  }
 public void run() {
   Assert.areEqual(_idx, _counter.value);
   _counter.value++;
   if (_fail) {
     Assert.fail();
   }
 }
 private void checkConsistency() {
   ConsistencyReport report =
       new ConsistencyChecker((LocalObjectContainer) container()).checkSlotConsistency();
   if (!report.consistent()) {
     Assert.fail(report.toString());
   }
 }
 public void testInt16ToBytesUpperBoundary() throws Exception {
   Assert.assertArrayEquals(new byte[] {(byte) 255, 127}, Toolbox.int16ToBytes(32767));
   try {
     Toolbox.int16ToBytes(32768);
     Assert.fail();
   } catch (IllegalArgumentException ex) {
   }
 }
 @Test
 public void testCopyIntoByteArrayNullArgument() throws Exception {
   try {
     Toolbox.copyIntoByteArray(null, 0, src);
     Assert.fail();
   } catch (NullPointerException ex) {
   }
 }
 @Test
 public void testCopyIntoByteArrayFromMinus() throws Exception {
   try {
     Toolbox.copyIntoByteArray(dest, -2, src);
     Assert.fail();
   } catch (IllegalArgumentException ex) {
   }
 }
 @Test
 public void testBytesToUint16TooLittleBytes() throws Exception {
   try {
     Toolbox.bytesToUint16(new byte[] {1, 2, 3}, 2);
     Assert.fail();
   } catch (IllegalArgumentException ex) {
   }
 }
 com.u2d.generated.FormatEnum castJmatterObject(Object object) {
   try {
     com.u2d.generated.FormatEnum output = (com.u2d.generated.FormatEnum) object;
     return output;
   } catch (Exception e) {
     Assert.fail(e.getMessage());
     return null;
   }
 }
 @Test
 public void testUint16ToBytesUpperBoundary() throws Exception {
   Assert.assertArrayEquals(new byte[] {(byte) 255, (byte) 255}, Toolbox.uint16ToBytes(65535));
   try {
     Toolbox.uint16ToBytes(65536);
     Assert.fail();
   } catch (IllegalArgumentException ex) {
   }
 }
 @Test
 public void testUint32ToBytesLowerBoundary() throws Exception {
   Assert.assertArrayEquals(new byte[] {0, 0, 0, 0}, Toolbox.uint32ToBytes(0));
   try {
     Toolbox.uint32ToBytes(-1);
     Assert.fail();
   } catch (IllegalArgumentException ex) {
   }
 }
Exemple #19
0
 protected void waitForDelete(String tableName) throws Exception {
   for (int i = 0; i < MAX_WAIT_ITERATION; i++) {
     if (!admin.tableExists(tableName)) {
       return;
     }
     Thread.sleep(WAIT_INTERVAL);
   }
   Assert.fail(getMethodName() + " failed");
 }
 org.jts.jsidl.binding.FormatEnum castJaxbObject(Object object) {
   try {
     org.jts.jsidl.binding.FormatEnum output = (org.jts.jsidl.binding.FormatEnum) object;
     return output;
   } catch (Exception e) {
     Assert.fail(e.getMessage());
     return null;
   }
 }
 /**
  * Directly create a table in the database. This can be used to simulate a second EAP node
  * creating a new table.
  *
  * @see JdbcContentPersistenceService#ensureTableExists
  * @param tableName table name to create
  */
 protected void createTable(String tableName) {
   try {
     final Connection conn = this.getTested().searchiskoDs.getConnection();
     conn.prepareStatement("create table " + tableName).execute();
     conn.commit();
   } catch (SQLException e) {
     Assert.fail(e.getMessage());
   }
 }
 @Before
 public void setUp() {
   try {
     File tempDir = FileUtils.createTempDir(root, null);
     provider = new StringTableProvider(tempDir.getPath(), false);
   } catch (ValidityCheckFailedException ex) {
     Assert.fail("validity check failed: " + ex.getMessage());
   }
 }
 @Test
 public void testBytesToUint16LowerBoundary() throws Exception {
   Assert.assertEquals(801, Toolbox.bytesToUint16(new byte[] {33, 3, 73, 123, 21}, 0));
   try {
     Assert.assertEquals(801, Toolbox.bytesToUint16(new byte[] {33, 3, 73, 123, 21}, -1));
     Assert.fail();
   } catch (Exception ex) {
   }
 }
 @Test
 public void testInt32ToBytesLowerBoundary() throws Exception {
   Assert.assertArrayEquals(new byte[] {0, 0, 0, (byte) 128}, Toolbox.int32ToBytes(-2147483648));
   try {
     Toolbox.int32ToBytes(-2147483649L);
     Assert.fail();
   } catch (IllegalArgumentException ex) {
   }
 }
  @Test
  public void testBytesToSint32InvalidOffset() throws Exception {
    try {
      Toolbox.bytesToSint32(new byte[] {1, 2, 3, 4, 5}, -1);
      Assert.fail();
    } catch (Exception ex) {
    }

    try {
      Toolbox.bytesToSint32(new byte[] {1, 2, 3, 4, 5}, 2);
      Assert.fail();
    } catch (Exception ex) {
    }

    try {
      Toolbox.bytesToSint32(new byte[] {1, 2, 3, 4, 5}, 12);
      Assert.fail();
    } catch (Exception ex) {
    }
  }
 @Before
 public void createMetaFolder() {
   config.set(DistCpConstants.CONF_LABEL_META_FOLDER, "/meta");
   Path meta = new Path("/meta");
   try {
     cluster.getFileSystem().mkdirs(meta);
   } catch (IOException e) {
     LOG.error("Exception encountered while creating meta folder", e);
     Assert.fail("Unable to create meta folder");
   }
 }
Exemple #27
0
 protected static void fail(String msg, EvalResult result) {
   System.err.println(" --- " + msg + ":");
   System.err.println(" --- actual output: ");
   System.err.println(result.stdout);
   System.err.println(" --- actual error output: ");
   System.err.println(result.stderr);
   System.err.println(" --- actual result: ");
   System.err.println(result.result);
   System.err.println(" --- end of report ---");
   Assert.fail();
 }
  @Test
  public void testAtomicCommitExistingFinal() {
    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));
      fs.mkdirs(new Path(finalPath));

      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.assertTrue(fs.exists(new Path(finalPath)));
      try {
        committer.commitJob(jobContext);
        Assert.fail("Should not be able to atomic-commit to pre-existing path.");
      } catch (Exception exception) {
        Assert.assertTrue(fs.exists(new Path(workPath)));
        Assert.assertTrue(fs.exists(new Path(finalPath)));
        LOG.info("Atomic-commit Test pass.");
      }

    } catch (IOException e) {
      LOG.error("Exception encountered while testing for atomic commit.", e);
      Assert.fail("Atomic commit failure");
    } finally {
      TestDistCpUtils.delete(fs, workPath);
      TestDistCpUtils.delete(fs, finalPath);
    }
  }
  @Before
  /** Setup the database and unmarshaller before we run the unit tests */
  public void setup() {
    seedDatabase();

    try {
      jc = JAXBContext.newInstance("org.jts.jsidl.binding");
      unmarshaller = jc.createUnmarshaller();
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }
  }
 @Test
 public void testBytesToUint32LowerBoundary() throws Exception {
   Assert.assertEquals(
       1234567890, Toolbox.bytesToUint32(new byte[] {(byte) 210, 2, (byte) 150, 73, 123, 21}, 0));
   try {
     Assert.assertEquals(
         1234567890,
         Toolbox.bytesToUint32(new byte[] {(byte) 210, 2, (byte) 150, 73, 123, 21}, -1));
     Assert.fail();
   } catch (Exception ex) {
   }
 }