/** * Checks whether callable throws exception, which is itself of a specified * class, or has a cause of the specified class. * * @param runnable Runnable. * @param cls Expected class. * @return Thrown throwable. */ @Nullable public static Throwable assertThrowsWithCause(Runnable runnable, Class<? extends Throwable> cls) { return assertThrowsWithCause(new Callable<Integer>() { @Override public Integer call() throws Exception { runnable.run(); return 0; } }, cls); }
@Override public void run() throws Exception { Throwable t = GridTestUtils.assertThrowsWithCause(new Callable<Object>() { @Override public Object call() throws Exception { cache.putAll(values); return null; } }, IgniteSQLException.class); IgniteSQLException ex = X.cause(t, IgniteSQLException.class); assertNotNull(ex); assertTrue(ex.getMessage().contains(ERR_MSG)); assertEquals(isLocalAtomic() ? expAtomicCacheSize : 0, cache.size()); } });
/** */ @Test public void testNodeCantJoinWithDifferentKeyStore() throws Exception { startGrid(GRID_0); assertThrowsWithCause(() -> { try { startGrid(GRID_2); } catch (Exception e) { throw new RuntimeException(e); } }, IgniteCheckedException.class); }
/** */ @Test public void testNodeCantJoinWithoutEncryptionSpi() throws Exception { startGrid(GRID_0); assertThrowsWithCause(() -> { try { startGrid(GRID_1); } catch (Exception e) { throw new RuntimeException(e); } }, IgniteCheckedException.class); }
/** */ protected void checkSQLThrows(String sql, String sqlStateCode, Object... args) { IgniteSQLException err = (IgniteSQLException)GridTestUtils.assertThrowsWithCause(() -> { execSQL(sql, args); return 0; }, IgniteSQLException.class); assertEquals(err.sqlState(), sqlStateCode); }
/** @throws Exception If failed. */ @Test public void testCantStartWithEmptyParam() throws Exception { GridTestUtils.assertThrowsWithCause(() -> { EncryptionSpi encSpi = new KeystoreEncryptionSpi(); encSpi.spiStart("default"); }, IgniteException.class); }
/** * @param sql Sql. */ private void assertSqlError(final String sql) { Throwable t = GridTestUtils.assertThrowsWithCause(new Callable<Void>() { @Override public Void call() { execSql(sql); return null; } }, IgniteSQLException.class); IgniteSQLException sqlE = X.cause(t, IgniteSQLException.class); assert sqlE != null; assertEquals(IgniteQueryErrorCode.UNSUPPORTED_OPERATION, sqlE.statusCode()); }
@SuppressWarnings({"unchecked", "ThrowableNotThrown"}) private void checkExplicitMvccInvoke(Ignite node, IgniteCache cache, TransactionConcurrency txConcurrency, TransactionIsolation txIsolation) { try (final Transaction tx = node.transactions().txStart(txConcurrency, txIsolation)) { cache.put(KEY, WRONG_VALUE); GridTestUtils.assertThrowsWithCause(new Callable<Object>() { @Override public Object call() throws Exception { cache.invoke(KEY, createEntryProcessor()); fail("Should never happened."); tx.commit(); return null; } }, UnsupportedOperationException.class); } }
/** @throws Exception If failed. */ @Test public void testCantStartKeystoreDoesntExists() throws Exception { GridTestUtils.assertThrowsWithCause(() -> { KeystoreEncryptionSpi encSpi = new KeystoreEncryptionSpi(); encSpi.setKeyStorePath("/ignite/is/cool/path/doesnt/exists"); encSpi.setKeyStorePassword(KEYSTORE_PASSWORD.toCharArray()); encSpi.spiStart("default"); }, IgniteException.class); }
/** @throws Exception If failed. */ @Test public void testCantStartWithoutPassword() throws Exception { GridTestUtils.assertThrowsWithCause(() -> { KeystoreEncryptionSpi encSpi = new KeystoreEncryptionSpi(); encSpi.setKeyStorePath("/ignite/is/cool/path/doesnt/exists"); encSpi.spiStart("default"); }, IgniteException.class); }
/** */ @Test public void testNodeCantJoinWithSameNameButNotEncCache() throws Exception { configureCache = true; IgniteEx grid0 = startGrid(GRID_0); grid0.cluster().active(true); assertThrowsWithCause(() -> { try { startGrid(GRID_5); } catch (Exception e) { throw new RuntimeException(e); } }, IgniteCheckedException.class); }
/** */ @Test public void testNodeCantJoinWithSameNameButEncCache() throws Exception { configureCache = true; IgniteEx grid0 = startGrid(GRID_5); grid0.cluster().active(true); assertThrowsWithCause(() -> { try { startGrid(GRID_0); } catch (Exception e) { throw new RuntimeException(e); } }, IgniteCheckedException.class); } }
/** {@inheritDoc} */ @Override protected void checkSQLThrows(String sql, String sqlStateCode, Object... args) { runSQL("BEGIN TRANSACTION"); IgniteSQLException err = (IgniteSQLException)GridTestUtils.assertThrowsWithCause(() -> { runSQL(sql, args); return 0; }, IgniteSQLException.class); runSQL("ROLLBACK TRANSACTION"); assertEquals(err.sqlState(), sqlStateCode); }
/** * @throws Exception In case of an error. */ @Test public void testThrowingExceptionOnUndeployUsingPuplicApiWhileClientDisconnected() throws Exception { runTaskWhenDisconnected(() -> { GridTestUtils.assertThrowsWithCause(() -> client().services().cancelAll(), IgniteClientDisconnectedException.class); }); }
@Override public void applyx(Ignite ignite, final IgniteCache<Integer, Integer> cache) throws Exception { for (CI1Exc<Transaction> txOperation : SUSPENDED_TX_PROHIBITED_OPS) { for (TransactionIsolation isolation : TransactionIsolation.values()) { Transaction tx = ignite.transactions().txStart(OPTIMISTIC, isolation); cache.put(1, 1); tx.suspend(); GridTestUtils.assertThrowsWithCause(txOperation, tx, IgniteException.class); tx.resume(); tx.close(); assertNull(cache.get(1)); } } } });
/** * @throws Exception In case of an error. */ @Test public void testThrowingExceptionOnDeployUsingPuplicApiWhileClientDisconnected() throws Exception { runTaskWhenDisconnected(() -> { GridTestUtils.assertThrowsWithCause( () -> client().services().deployNodeSingletonAsync("testService", MyServiceFactory.create()), IgniteClientDisconnectedException.class); }); }
/** @throws Exception If failed. */ @Test public void testCreateEncryptedNotPersistedCacheFail() throws Exception { GridTestUtils.assertThrowsWithCause(() -> { CacheConfiguration<Long, String> ccfg = new CacheConfiguration<>(NO_PERSISTENCE_REGION); ccfg.setEncryptionEnabled(true); ccfg.setDataRegionName(NO_PERSISTENCE_REGION); grid(0).createCache(ccfg); }, IgniteCheckedException.class); }
/** @throws Exception If failed. */ @Test public void testCreateNotEncryptedCacheInEncryptedGroupFails() throws Exception { createEncryptedCache(ENCRYPTED_CACHE + "3", ENCRYPTED_GROUP + "3"); IgniteEx grid = grid(0); GridTestUtils.assertThrowsWithCause(() -> { grid.createCache(new CacheConfiguration<>(ENCRYPTED_CACHE + "4") .setEncryptionEnabled(false) .setGroupName(ENCRYPTED_GROUP + "3")); }, IgniteCheckedException.class); }
/** * @throws Exception In case of an error. */ @Test public void testThrowingExceptionOnUndeployUsingInternalApiWhileClientDisconnectedTest() throws Exception { runTaskWhenDisconnected(() -> { GridTestUtils.assertThrowsWithCause(() -> client().context().service().cancelAll().get(), IgniteClientDisconnectedCheckedException.class); }); }
/** * @throws Exception In case of an error. */ @Test public void testThrowingExceptionOnDeployUsingInternalApiWhileClientDisconnected() throws Exception { runTaskWhenDisconnected(() -> { GridTestUtils.assertThrowsWithCause(() -> client().context().service().deployNodeSingleton( new ClusterGroupAdapter(), "testService", MyServiceFactory.create()).get(), IgniteClientDisconnectedCheckedException.class); }); }