public void run() { try { try { if (!cmd.hasOption(SILENT_OPTION)) { System.out.printf("%sLoading schema from %s:%s%s", ANSI_RED, host, port, ANSI_RESET); System.out.flush(); } String cfids = cmd.getOptionValue(CFID_OPTION, ""); cluster = CassandraUtils.loadTablesFromRemote(host, port, cfids); } finally { System.out.print(ANSI_RESET); } for (String target : cmd.getArgs()) { File targetFile = new File(target); if (!targetFile.exists()) { if (!cmd.hasOption(SILENT_OPTION)) { System.out.print("\r" + ANSI_RESET + Strings.repeat(" ", 60) + "\r"); } System.err.println("Non-existant target provided: " + target); } else { if (!cmd.hasOption(SILENT_OPTION)) { System.out.print("\r" + ANSI_RESET + Strings.repeat(" ", 60) + "\r"); System.out.println("\u001B[1;34m" + targetFile.getAbsolutePath()); System.out.println(ANSI_CYAN + Strings.repeat("=", targetFile.getAbsolutePath().length())); System.out.print(ANSI_RESET); } MutationReplayer replayer = null; if (cmd.hasOption(REPLAY_OPTION)) { replayer = new MutationReplayer(cluster); } walkMutations(targetFile, System.out, replayer); } } } catch (Exception e) { e.printStackTrace(); } finally { IOUtil.closeQuietly(cluster); } }
@Before public void createCredentials() throws IOException { File tempDir = tempFolder.newFolder(); File clientJson = new File(tempDir, "client.json"); IOUtil.writeText("{\"client_id\":\"abcdefg \",\"client_secret\":\"geheim\"}", clientJson); File userJson = new File(tempDir, "user.json"); IOUtil.writeText("{\"application_username\":\"klaus \",\"application_password\":\"geheim\"}", userJson); System.setProperty(CREDENTIALS_DIR, tempDir.getAbsolutePath()); }
@Test public void runAccessTokenRefresher() throws IOException, InterruptedException { File tempDir = tempFolder.newFolder(); File clientJson = new File(tempDir, "client.json"); IOUtil.writeText("{\"client_id\":\"abcdefg \",\"client_secret\":\"geheim\"}", clientJson); File userJson = new File(tempDir, "user.json"); IOUtil.writeText("{\"application_username\":\"klaus \",\"application_password\":\"geheim\"}", userJson); System.setProperty(CREDENTIALS_DIR, tempDir.getAbsolutePath()); ClientCredentialsProvider ccp = new JsonFileBackedClientCredentialsProvider(clientJson); UserCredentialsProvider ucp = new JsonFileBackedUserCredentialsProvider(userJson); HttpProviderFactory hpf = Mockito.mock(HttpProviderFactory.class); AccessTokensBuilder accessTokenBuilder = Tokens.createAccessTokensWithUri(uri) .usingClientCredentialsProvider(ccp) .usingUserCredentialsProvider(ucp) .usingHttpProviderFactory(hpf) .manageToken("TR_TEST") .done() .manageToken("TR_TEST_1") .done() .manageToken("TR_TEST_2") .done(); HttpProvider httpProvider = Mockito.mock(HttpProvider.class); Mockito.when(hpf.create(Mockito.any(ClientCredentials.class), Mockito.any(UserCredentials.class), Mockito.any(URI.class), Mockito.any(HttpConfig.class))).thenReturn(httpProvider); Mockito.when(httpProvider.createToken(Mockito.any(AccessTokenConfiguration.class))) .thenReturn(new AccessToken("123456789", "BEARER", 2, new Date(System.currentTimeMillis() + 15000))) .thenThrow(new RuntimeException("DO NOT FAIL ALL CONFIGURATIONS")) .thenReturn(new AccessToken("123456789", "BEARER", 2, new Date(System.currentTimeMillis() + 15000))) .thenReturn(new AccessToken("123456789", "BEARER", 2, new Date(System.currentTimeMillis() + 15000))) .thenThrow(new RuntimeException("DO NOT FAIL ALL CONFIGURATIONS")) .thenReturn(new AccessToken("123456789", "BEARER", 2, new Date(System.currentTimeMillis() + 15000))); accessTokens = accessTokenBuilder.start(); Assertions.assertThat(accessTokens).isNotNull(); TimeUnit.SECONDS.sleep(30); Mockito.verify(httpProvider, Mockito.atLeastOnce()).createToken(Mockito.any(AccessTokenConfiguration.class)); }