Java Code Examples for org.apache.bookkeeper.util.IOUtils#createTempDir()
The following examples show how to use
org.apache.bookkeeper.util.IOUtils#createTempDir() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDistributedLogBase.java From distributedlog with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupCluster() throws Exception { File zkTmpDir = IOUtils.createTempDir("zookeeper", "distrlog"); tmpDirs.add(zkTmpDir); Pair<ZooKeeperServerShim, Integer> serverAndPort = LocalDLMEmulator.runZookeeperOnAnyPort(zkTmpDir); zks = serverAndPort.getLeft(); zkPort = serverAndPort.getRight(); bkutil = LocalDLMEmulator.newBuilder() .numBookies(numBookies) .zkHost("127.0.0.1") .zkPort(zkPort) .serverConf(DLMTestUtil.loadTestBkConf()) .shouldStartZK(false) .build(); bkutil.start(); zkServers = "127.0.0.1:" + zkPort; Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { LOG.warn("Uncaught exception at Thread {} : ", t.getName(), e); } }); }
Example 2
Source File: TestDLMTestUtil.java From distributedlog with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testRunZookeeperOnAnyPort() throws Exception { Pair<ZooKeeperServerShim, Integer> serverAndPort1 = null; Pair<ZooKeeperServerShim, Integer> serverAndPort2 = null; Pair<ZooKeeperServerShim, Integer> serverAndPort3 = null; try { File zkTmpDir1 = IOUtils.createTempDir("zookeeper1", "distrlog"); serverAndPort1 = LocalDLMEmulator.runZookeeperOnAnyPort(7000, zkTmpDir1); File zkTmpDir2 = IOUtils.createTempDir("zookeeper2", "distrlog"); serverAndPort2 = LocalDLMEmulator.runZookeeperOnAnyPort(7000, zkTmpDir2); File zkTmpDir3 = IOUtils.createTempDir("zookeeper3", "distrlog"); serverAndPort3 = LocalDLMEmulator.runZookeeperOnAnyPort(7000, zkTmpDir3); } catch (Exception ex) { if (null != serverAndPort1) { serverAndPort1.getLeft().stop(); } if (null != serverAndPort2) { serverAndPort2.getLeft().stop(); } if (null != serverAndPort3) { serverAndPort3.getLeft().stop(); } } }
Example 3
Source File: OutOfProcessAdapter.java From pravega with Apache License 2.0 | 6 votes |
private void createSegmentStoreFileSystem() throws IOException { File rootDir = this.segmentStoreRoot.get(); if (rootDir == null || !rootDir.exists()) { rootDir = IOUtils.createTempDir("selftest.segmentstore.", ""); rootDir.deleteOnExit(); this.segmentStoreRoot.set(rootDir); } // Config file. File configFile = new File(getSegmentStoreConfigFilePath()); configFile.delete(); configFile.createNewFile(); log("SegmentStore Config: '%s'.", configFile.getAbsolutePath()); // Storage. File storageDir = new File(getSegmentStoreStoragePath()); storageDir.delete(); storageDir.mkdir(); log("SegmentStore Storage: '%s/'.", storageDir.getAbsolutePath()); this.builderConfig.store(configFile); }
Example 4
Source File: TestDistributedLogBase.java From distributedlog with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupCluster() throws Exception { File zkTmpDir = IOUtils.createTempDir("zookeeper", "distrlog"); tmpDirs.add(zkTmpDir); Pair<ZooKeeperServerShim, Integer> serverAndPort = LocalDLMEmulator.runZookeeperOnAnyPort(zkTmpDir); zks = serverAndPort.getLeft(); zkPort = serverAndPort.getRight(); bkutil = LocalDLMEmulator.newBuilder() .numBookies(numBookies) .zkHost("127.0.0.1") .zkPort(zkPort) .serverConf(DLMTestUtil.loadTestBkConf()) .shouldStartZK(false) .build(); bkutil.start(); zkServers = "127.0.0.1:" + zkPort; }
Example 5
Source File: TestDLMTestUtil.java From distributedlog with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testRunZookeeperOnAnyPort() throws Exception { Pair<ZooKeeperServerShim, Integer> serverAndPort1 = null; Pair<ZooKeeperServerShim, Integer> serverAndPort2 = null; Pair<ZooKeeperServerShim, Integer> serverAndPort3 = null; try { File zkTmpDir1 = IOUtils.createTempDir("zookeeper1", "distrlog"); serverAndPort1 = LocalDLMEmulator.runZookeeperOnAnyPort(7000, zkTmpDir1); File zkTmpDir2 = IOUtils.createTempDir("zookeeper2", "distrlog"); serverAndPort2 = LocalDLMEmulator.runZookeeperOnAnyPort(7000, zkTmpDir2); File zkTmpDir3 = IOUtils.createTempDir("zookeeper3", "distrlog"); serverAndPort3 = LocalDLMEmulator.runZookeeperOnAnyPort(7000, zkTmpDir3); } catch (Exception ex) { if (null != serverAndPort1) { serverAndPort1.getLeft().stop(); } if (null != serverAndPort2) { serverAndPort2.getLeft().stop(); } if (null != serverAndPort3) { serverAndPort3.getLeft().stop(); } } }
Example 6
Source File: DistributedLogCluster.java From distributedlog with Apache License 2.0 | 5 votes |
private DistributedLogCluster(DistributedLogConfiguration dlConf, ServerConfiguration bkConf, int numBookies, boolean shouldStartZK, String zkServers, int zkPort, boolean shouldStartProxy, int proxyPort, boolean thriftmux) throws Exception { this.dlConf = dlConf; if (shouldStartZK) { File zkTmpDir = IOUtils.createTempDir("zookeeper", "distrlog"); tmpDirs.add(zkTmpDir); if (0 == zkPort) { Pair<ZooKeeperServerShim, Integer> serverAndPort = LocalDLMEmulator.runZookeeperOnAnyPort(zkTmpDir); this.zks = serverAndPort.getLeft(); zkPort = serverAndPort.getRight(); } else { this.zks = LocalBookKeeper.runZookeeper(1000, zkPort, zkTmpDir); } } else { this.zks = null; } this.dlmEmulator = LocalDLMEmulator.newBuilder() .numBookies(numBookies) .zkHost(zkServers) .zkPort(zkPort) .serverConf(bkConf) .shouldStartZK(false) .build(); this.shouldStartProxy = shouldStartProxy; this.proxyPort = proxyPort; this.thriftmux = thriftmux; }
Example 7
Source File: LocalDLMEmulator.java From distributedlog with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { try { if (args.length < 1) { System.out.println("Usage: LocalDLEmulator <zk_port>"); System.exit(-1); } final int zkPort = Integer.parseInt(args[0]); final File zkDir = IOUtils.createTempDir("distrlog", "zookeeper"); final LocalDLMEmulator localDlm = LocalDLMEmulator.newBuilder() .zkPort(zkPort) .build(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { localDlm.teardown(); FileUtils.forceDeleteOnExit(zkDir); System.out.println("ByeBye!"); } catch (Exception e) { // do nothing } } }); localDlm.start(); System.out.println(String.format( "DistributedLog Sandbox is running now. You could access distributedlog://%s:%s", DEFAULT_ZK_HOST, zkPort)); } catch (Exception ex) { System.out.println("Exception occurred running emulator " + ex); } }
Example 8
Source File: ZooKeeperClusterTestCase.java From distributedlog with Apache License 2.0 | 5 votes |
@BeforeClass public static void setupZooKeeper() throws Exception { zkDir = IOUtils.createTempDir("zookeeper", ZooKeeperClusterTestCase.class.getName()); Pair<ZooKeeperServerShim, Integer> serverAndPort = LocalDLMEmulator.runZookeeperOnAnyPort(zkDir); zks = serverAndPort.getLeft(); zkPort = serverAndPort.getRight(); zkServers = "127.0.0.1:" + zkPort; }
Example 9
Source File: BookKeeperServiceRunner.java From pravega with Apache License 2.0 | 5 votes |
private BookieServer runBookie(int bkPort) throws Exception { // Attempt to reuse an existing data directory. This is useful in case of stops & restarts, when we want to preserve // already committed data. File journalDir = this.journalDirs.getOrDefault(bkPort, null); if (journalDir == null) { journalDir = IOUtils.createTempDir("bookiejournal_" + bkPort, "_test"); log.info("Journal Dir[{}]: {}.", bkPort, journalDir.getPath()); this.journalDirs.put(bkPort, journalDir); setupTempDir(journalDir); } File ledgerDir = this.ledgerDirs.getOrDefault(bkPort, null); if (ledgerDir == null) { ledgerDir = Strings.isNullOrEmpty(this.ledgersDir) ? null : new File(this.ledgersDir); ledgerDir = IOUtils.createTempDir("bookieledger_" + bkPort, "_test", ledgerDir); log.info("Ledgers Dir[{}]: {}.", bkPort, ledgerDir.getPath()); this.ledgerDirs.put(bkPort, ledgerDir); setupTempDir(ledgerDir); } val conf = new ServerConfiguration(); conf.setBookiePort(bkPort); conf.setMetadataServiceUri("zk://" + LOOPBACK_ADDRESS.getHostAddress() + ":" + this.zkPort + ledgersPath); conf.setJournalDirName(journalDir.getPath()); conf.setLedgerDirNames(new String[]{ledgerDir.getPath()}); conf.setAllowLoopback(true); conf.setJournalAdaptiveGroupWrites(true); if (secureBK) { conf.setTLSProvider("OpenSSL"); conf.setTLSProviderFactoryClass("org.apache.bookkeeper.tls.TLSContextFactory"); conf.setTLSKeyStore(this.tLSKeyStore); conf.setTLSKeyStorePasswordPath(this.tLSKeyStorePasswordPath); } log.info("Starting Bookie at port " + bkPort); val bs = new BookieServer(conf); bs.start(); return bs; }
Example 10
Source File: LocalDLMEmulator.java From distributedlog with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { try { if (args.length < 1) { System.out.println("Usage: LocalDLEmulator <zk_port>"); System.exit(-1); } final int zkPort = Integer.parseInt(args[0]); final File zkDir = IOUtils.createTempDir("distrlog", "zookeeper"); final LocalDLMEmulator localDlm = LocalDLMEmulator.newBuilder() .zkPort(zkPort) .build(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { localDlm.teardown(); FileUtils.deleteDirectory(zkDir); System.out.println("ByeBye!"); } catch (Exception e) { // do nothing } } }); localDlm.start(); System.out.println(String.format( "DistributedLog Sandbox is running now. You could access distributedlog://%s:%s", DEFAULT_ZK_HOST, zkPort)); } catch (Exception ex) { System.out.println("Exception occurred running emulator " + ex); } }
Example 11
Source File: ZooKeeperClusterTestCase.java From distributedlog with Apache License 2.0 | 5 votes |
@BeforeClass public static void setupZooKeeper() throws Exception { zkDir = IOUtils.createTempDir("zookeeper", ZooKeeperClusterTestCase.class.getName()); Pair<ZooKeeperServerShim, Integer> serverAndPort = LocalDLMEmulator.runZookeeperOnAnyPort(zkDir); zks = serverAndPort.getLeft(); zkPort = serverAndPort.getRight(); zkServers = "127.0.0.1:" + zkPort; }
Example 12
Source File: DistributedLogCluster.java From distributedlog with Apache License 2.0 | 5 votes |
private DistributedLogCluster(DistributedLogConfiguration dlConf, ServerConfiguration bkConf, int numBookies, boolean shouldStartZK, String zkServers, int zkPort, boolean shouldStartProxy, int proxyPort) throws Exception { this.dlConf = dlConf; if (shouldStartZK) { File zkTmpDir = IOUtils.createTempDir("zookeeper", "distrlog"); tmpDirs.add(zkTmpDir); if (0 == zkPort) { Pair<ZooKeeperServerShim, Integer> serverAndPort = LocalDLMEmulator.runZookeeperOnAnyPort(zkTmpDir); this.zks = serverAndPort.getLeft(); zkPort = serverAndPort.getRight(); } else { this.zks = LocalBookKeeper.runZookeeper(1000, zkPort, zkTmpDir); } } else { this.zks = null; } this.dlmEmulator = LocalDLMEmulator.newBuilder() .numBookies(numBookies) .zkHost(zkServers) .zkPort(zkPort) .serverConf(bkConf) .shouldStartZK(false) .build(); this.shouldStartProxy = shouldStartProxy; this.proxyPort = proxyPort; }