/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true); startGrids(NODES_COUNT); grid(0).cluster().active(true); actxDflt = grid(0).context().authentication().authenticate(User.DFAULT_USER_NAME, "ignite"); assertNotNull(actxDflt); }
/** */ private IgniteInternalFuture loopServerRestarts() { return GridTestUtils.runAsync(() -> { try { for (int i = 0; i < RESTARTS; ++i) { stopGrid(1); U.sleep(500); startGrid(1); U.sleep(500); } } catch (Exception e) { e.printStackTrace(System.err); fail("Unexpected exception on server restart: " + e.getMessage()); } }); } }
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { stopAllGrids(); super.afterTest(); }
grid(CLI_NODE).context().authentication().addUser("test" + i, "passwd_test" + i); int nodeIdx = RND.nextInt(NODES_COUNT - 1); stopGrid(nodeIdx); startGrid(nodeIdx); fail("Unexpected exception on server restart: " + e.getMessage()); AuthorizationContext actx = grid(CLI_NODE).context().authentication() .authenticate(user, "passwd_" + user); assertNotNull(actx); if (!serverDownMessage(e.getMessage())) { e.printStackTrace(); fail("Unexpected exception: " + e.getMessage()); fail("Unexpected exception: " + e.getMessage());
grid(0).context().authentication().addUser(user, "init"); fail("Unexpected exception on add / remove"); grid(0).context().authentication().updateUser(user, "passwd_" + user); fail("Unexpected exception on add / remove"); stopGrid(0, true); startGrid(0); AuthorizationContext actx = grid(0).context().authentication().authenticate("ignite", "ignite");
/** * @throws Exception If failed. */ @Test public void testConcurrentAddUpdateRemoveNodeRestartServer() throws Exception { IgniteInternalFuture restartFut = loopServerRestarts(); AuthorizationContext.context(actxDflt); final AtomicInteger usrCnt = new AtomicInteger(); GridTestUtils.runMultiThreaded(() -> { AuthorizationContext.context(actxDflt); String user = "test" + usrCnt.getAndIncrement(); try { while (!restartFut.isDone()) { grid(CLI_NODE).context().authentication().addUser(user, "init"); grid(CLI_NODE).context().authentication().updateUser(user, "passwd_" + user); grid(CLI_NODE).context().authentication().removeUser(user); } } catch (Exception e) { e.printStackTrace(); fail("Unexpected exception on add / remove"); } }, 10, "user-op"); restartFut.get(); }
@Test public void testConcurrentAddUpdateRemoveNodeRestartCoordinator() throws Exception { final IgniteInternalFuture restartFut = restartCoordinator(); switch (state) { case 0: grid(CLI_NODE).context().authentication().addUser(user, "passwd_" + user); grid(CLI_NODE).context().authentication().updateUser(user, "new_passwd_" + user); grid(CLI_NODE).context().authentication().removeUser(user); fail("Invalid state: " + state); fail("Unexpected exception on user operation"); fail();
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); if (getTestIgniteInstanceIndex(igniteInstanceName) == CLI_NODE) cfg.setClientMode(true); cfg.setAuthenticationEnabled(true); cfg.setDataStorageConfiguration(new DataStorageConfiguration() .setDefaultDataRegionConfiguration(new DataRegionConfiguration() .setMaxSize(200L * 1024 * 1024) .setPersistenceEnabled(true))); return cfg; }
/** * @throws Exception If failed. */ @Test public void testConcurrentFailedOperationNodeRestartServer() throws Exception { IgniteInternalFuture restartFut = loopServerRestarts(); AuthorizationContext.context(actxDflt); grid(CLI_NODE).context().authentication().addUser("test", "test"); GridTestUtils.runMultiThreaded(() -> { AuthorizationContext.context(actxDflt); try { while (!restartFut.isDone()) { GridTestUtils.assertThrows(log, () -> { grid(CLI_NODE).context().authentication().addUser("test", "test"); return null; }, UserManagementException.class, "User already exists"); } } catch (Exception e) { e.printStackTrace(); fail("Unexpected error on failed operation"); } }, 10, "user-op"); restartFut.get(); }
/** * @return Future. */ private IgniteInternalFuture restartCoordinator() { return GridTestUtils.runAsync(() -> { try { int restarts = 0; while (restarts < RESTARTS) { for (int i = 0; i < CLI_NODE; ++i, ++restarts) { if (restarts >= RESTARTS) break; stopGrid(i); U.sleep(500); startGrid(i); U.sleep(500); } } } catch (Exception e) { U.error(log, "Unexpected exception on coordinator restart", e); fail(); } }); }