use of java.lang.Exception in project jdk8u_jdk by JetBrains.
the class ProviderVersionCheck method main.
public static void main(String[] arg) throws Exception {
boolean failure = false;
for (Provider p : Security.getProviders()) {
System.out.print(p.getName() + " ");
if (p.getVersion() != 1.8d) {
System.out.println("failed. " + "Version received was " + p.getVersion());
failure = true;
} else {
System.out.println("passed.");
}
}
if (failure) {
throw new Exception("Provider(s) failed to have the expected " + "version value.");
}
}
use of java.lang.Exception in project jdk8u_jdk by JetBrains.
the class CipherInputStreamExceptions method gcm_oneReadByte.
/*
* Verify noexception thrown when 1 byte is read from a GCM stream
* and then closed
* This test:
* 1) Encrypt 100 bytes with AES/GCM/PKCS5Padding
* 2) Read one byte from the stream, expect no exception thrown.
* 4) Close stream,expect no exception thrown.
*/
static void gcm_oneReadByte() throws Exception {
System.out.println("Running gcm_oneReadByte test");
// Encrypt 100 bytes with AES/GCM/PKCS5Padding
byte[] ct = encryptedText("GCM", 100);
// Create stream for decryption
CipherInputStream in = getStream("GCM", ct);
try {
in.read();
System.out.println(" Pass.");
} catch (Exception e) {
System.out.println(" Fail: " + e.getMessage());
throw new RuntimeException(e.getCause());
}
}
use of java.lang.Exception in project voldemort by voldemort.
the class HdfsCopyStatsTest method testCopyStats.
@Test
public void testCopyStats() throws Exception {
destination = new File(testSourceDir.getAbsolutePath() + "_dest");
statsDir = HdfsCopyStats.getStatDir(destination);
if (statsDir != null)
HdfsFetcherAdvancedTest.deleteDir(statsDir);
List<String> expectedStatsFile = new ArrayList<String>();
for (int i = 0; i < maxStatsFile + 2; i++) {
destination = new File(testSourceDir.getAbsolutePath() + "_dest" + i);
String destName = destination.getName();
// Sleep to get last modified time stamp different for all files
// linux timestamp has second granularity, so sleep for a second
Thread.sleep(1000);
HdfsCopyStats stats = new HdfsCopyStats(testSourceDir.getAbsolutePath(), destination, enableStatsFile, maxStatsFile, isFileCopy, HdfsPathInfo.getTestObject(1000));
if (stats.getStatsFile() != null) {
expectedStatsFile.add(stats.getStatsFile().getName());
}
Random r = new Random();
for (int j = 0; j < 10; j++) {
File file = new File(destination, "file" + i);
stats.reportFileDownloaded(file, System.currentTimeMillis(), r.nextInt(), r.nextLong(), r.nextInt(), r.nextLong(), null);
}
Exception e = r.nextBoolean() ? null : new Exception();
stats.reportFileError(new File(destination, "error"), r.nextInt(), r.nextLong(), e);
stats.reportError("MyMessage", e);
stats.complete();
if (destination != null)
HdfsFetcherAdvancedTest.deleteDir(destination);
}
statsDir = HdfsCopyStats.getStatDir(destination);
if (enableStatsFile && isFileCopy == false) {
assertTrue("stats dir exists", statsDir.exists());
File[] statsFiles = statsDir.listFiles();
assertEquals("Number of files should be equal to the maxStatsFiles", maxStatsFile, statsFiles.length);
Set<String> actualStatsFile = new HashSet<String>();
for (File statFile : statsFiles) {
assertTrue("Size of the stat file should be greater than zero", statFile.length() > 0);
actualStatsFile.add(statFile.getName());
}
while (expectedStatsFile.size() > maxStatsFile) {
expectedStatsFile.remove(0);
}
assertEquals("Expected and actual files are different", new HashSet<String>(expectedStatsFile), actualStatsFile);
} else {
assertFalse("statsDir " + statsDir + " should not exist", statsDir.exists());
}
cleanUp();
}
use of java.lang.Exception in project voldemort by voldemort.
the class HdfsCopyStatsTest method testReportExceptionForStats.
@Test
public void testReportExceptionForStats() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Map<Exception, Map> config = new HashMap<Exception, Map>();
config.put(new Exception(new AuthenticationException("test")), buildMethodResultMap(1, 0, 0, 0, 0));
config.put(new FileNotFoundException(), buildMethodResultMap(0, 1, 0, 0, 0));
config.put(new IOException(), buildMethodResultMap(0, 0, 1, 0, 0));
config.put(new QuotaExceededException("test"), buildMethodResultMap(0, 0, 0, 1, 0));
config.put(new UnauthorizedStoreException("test"), buildMethodResultMap(0, 0, 0, 0, 1));
HdfsFetcherAggStats aggStats = HdfsFetcherAggStats.getStats();
for (Map.Entry<Exception, Map> entry : config.entrySet()) {
Exception e = entry.getKey();
Map<String, Long> methodResMap = entry.getValue();
Set<String> methodSet = methodResMap.keySet();
// Get result before invocation
Map<String, Long> beforeRes = invokeInternalMethod(aggStats, methodSet);
HdfsCopyStats.reportExceptionForStats(e);
// Get result after invocation
Map<String, Long> afterRes = invokeInternalMethod(aggStats, methodSet);
// Compare the difference
for (String methodName : methodSet) {
String msg = "Method expects " + methodResMap.get(methodName) + " with exception: " + e.getClass().getName();
assertEquals(msg, methodResMap.get(methodName).longValue(), afterRes.get(methodName).longValue() - beforeRes.get(methodName).longValue());
}
}
}
use of java.lang.Exception in project hive by apache.
the class TestJdbcDriver2 method testPrepareStatement.
@Test
public void testPrepareStatement() {
String sql = "FROM (SELECT 1 FROM " + tableName + " where 'not?param?not?param' <> 'not_param??not_param' and ?=? " + " and 1=? and 2=? and 3.0=? and 4.0=? and 'test\\'string\"'=? and 5=? and ?=? " + " and date '2012-01-01' = date ?" + " and timestamp '2012-04-22 09:00:00.123456789' = timestamp ?" + " ) t SELECT '2011-03-25' ddate,'China',true bv, 10 num LIMIT 1";
// executed twice: once with the typed ps setters, once with the generic setObject
try {
try (PreparedStatement ps = createPreapredStatementUsingSetXXX(sql);
ResultSet res = ps.executeQuery()) {
assertPreparedStatementResultAsExpected(res);
}
try (PreparedStatement ps = createPreapredStatementUsingSetObject(sql);
ResultSet res = ps.executeQuery()) {
assertPreparedStatementResultAsExpected(res);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
// set nothing for prepared sql
Exception expectedException = null;
try (PreparedStatement ps = con.prepareStatement(sql);
ResultSet ignored = ps.executeQuery()) {
} catch (Exception e) {
expectedException = e;
}
assertNotNull("Execute the un-setted sql statement should throw exception", expectedException);
// set some of parameters for prepared sql, not all of them.
expectedException = null;
try (PreparedStatement ps = con.prepareStatement(sql)) {
ps.setBoolean(1, true);
ps.setBoolean(2, true);
try (ResultSet ignored = ps.executeQuery()) {
}
} catch (Exception e) {
expectedException = e;
}
assertNotNull("Execute the invalid setted sql statement should throw exception", expectedException);
// set the wrong type parameters for prepared sql.
expectedException = null;
try (PreparedStatement ps = con.prepareStatement(sql)) {
// wrong type here
ps.setString(1, "wrong");
try (ResultSet res = ps.executeQuery()) {
assertFalse("ResultSet was not empty", res.next());
}
} catch (Exception e) {
expectedException = e;
}
assertNotNull("Execute the invalid setted sql statement should throw exception", expectedException);
// setObject to the yet unknown type java.util.Date
expectedException = null;
try (PreparedStatement ps = con.prepareStatement(sql)) {
ps.setObject(1, new Date());
try (ResultSet ignored = ps.executeQuery()) {
}
} catch (Exception e) {
expectedException = e;
}
assertNotNull("Setting to an unknown type should throw an exception", expectedException);
}
Aggregations