本文整理汇总了Java中org.apache.zookeeper.test.ClientBase.createTmpDir方法的典型用法代码示例。如果您正苦于以下问题:Java ClientBase.createTmpDir方法的具体用法?Java ClientBase.createTmpDir怎么用?Java ClientBase.createTmpDir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.test.ClientBase
的用法示例。
在下文中一共展示了ClientBase.createTmpDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MainThread
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
public MainThread(int clientPort) throws IOException {
super("Standalone server with clientPort:" + clientPort);
File tmpDir = ClientBase.createTmpDir();
confFile = new File(tmpDir, "zoo.cfg");
FileWriter fwriter = new FileWriter(confFile);
fwriter.write("tickTime=2000\n");
fwriter.write("initLimit=10\n");
fwriter.write("syncLimit=5\n");
fwriter.write("snapCount=1\n");
File dataDir = new File(tmpDir, "data");
if (!dataDir.mkdir()) {
throw new IOException("unable to mkdir " + dataDir);
}
// Convert windows path to UNIX to avoid problems with "\"
String dir = PathUtils.normalizeFileSystemPath(dataDir.toString());
fwriter.write("dataDir=" + dir + "\n");
fwriter.write("clientPort=" + clientPort + "\n");
fwriter.flush();
fwriter.close();
main = new TestMain();
}
示例2: setUp
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
this.count = 3;
this.peers = new HashMap<Long,QuorumServer>(count);
peerTmpdir = new File[count];
peerQuorumPort = new int[count];
peerClientPort = new int[count];
for(int i = 0; i < count; i++) {
peerQuorumPort[i] = PortAssignment.unique();
peerClientPort[i] = PortAssignment.unique();
peers.put(Long.valueOf(i),
new QuorumServer(i, "0.0.0.0",
peerQuorumPort[i],
PortAssignment.unique(), null));
peerTmpdir[i] = ClientBase.createTmpDir();
}
}
示例3: testSnapFilesEqualsToRetain
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
* Tests purge where the data directory contains snap files equals to the
* number of files to be retained
*/
@Test
public void testSnapFilesEqualsToRetain() throws Exception {
int nRecentCount = 3;
AtomicInteger offset = new AtomicInteger(0);
tmpDir = ClientBase.createTmpDir();
File version2 = new File(tmpDir.toString(), "version-2");
Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
version2.mkdir());
List<File> snaps = new ArrayList<File>();
List<File> logs = new ArrayList<File>();
createDataDirFiles(offset, nRecentCount, version2, snaps, logs);
FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
txnLog.close();
verifyFilesAfterPurge(snaps, true);
verifyFilesAfterPurge(logs, true);
}
示例4: internalTestSnapFilesEqualsToRetain
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
public void internalTestSnapFilesEqualsToRetain(boolean testWithPrecedingLogFile) throws Exception {
int nRecentCount = 3;
AtomicInteger offset = new AtomicInteger(0);
tmpDir = ClientBase.createTmpDir();
File version2 = new File(tmpDir.toString(), "version-2");
Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
version2.mkdir());
List<File> snaps = new ArrayList<File>();
List<File> logs = new ArrayList<File>();
createDataDirFiles(offset, nRecentCount, testWithPrecedingLogFile, version2, snaps, logs);
FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
txnLog.close();
verifyFilesAfterPurge(snaps, true);
verifyFilesAfterPurge(logs, true);
}
示例5: testJMXRegistrationWithNetty
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
@Test
public void testJMXRegistrationWithNetty() throws Exception {
String originalServerCnxnFactory = System
.getProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY);
System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY,
NettyServerCnxnFactory.class.getName());
try {
ClientBase.setupTestEnv();
File tmpDir_1 = ClientBase.createTmpDir();
ServerCnxnFactory server_1 = startServer(tmpDir_1);
File tmpDir_2 = ClientBase.createTmpDir();
ServerCnxnFactory server_2 = startServer(tmpDir_2);
server_1.shutdown();
server_2.shutdown();
deleteFile(tmpDir_1);
deleteFile(tmpDir_2);
} finally {
// setting back
if (originalServerCnxnFactory == null
|| originalServerCnxnFactory.isEmpty()) {
System.clearProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY);
} else {
System.setProperty(
ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY,
originalServerCnxnFactory);
}
}
}
示例6: testJMXRegistrationWithNIO
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
@Test
public void testJMXRegistrationWithNIO() throws Exception {
ClientBase.setupTestEnv();
File tmpDir_1 = ClientBase.createTmpDir();
ServerCnxnFactory server_1 = startServer(tmpDir_1);
File tmpDir_2 = ClientBase.createTmpDir();
ServerCnxnFactory server_2 = startServer(tmpDir_2);
server_1.shutdown();
server_2.shutdown();
deleteFile(tmpDir_1);
deleteFile(tmpDir_2);
}
示例7: testLostMessage
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
@Test
public void testLostMessage() throws Exception {
FastLeaderElection le[] = new FastLeaderElection[count];
LOG.info("TestLE: " + getTestName()+ ", " + count);
for(int i = 0; i < count; i++) {
int clientport = PortAssignment.unique();
peers.put(Long.valueOf(i),
new QuorumServer(i, "0.0.0.0", clientport,
PortAssignment.unique(), null));
tmpdir[i] = ClientBase.createTmpDir();
port[i] = clientport;
}
/*
* Start server 0
*/
QuorumPeer peer = new QuorumPeer(peers, tmpdir[1], tmpdir[1], port[1], 3, 1, 1000, 2, 2);
peer.startLeaderElection();
FLETestUtils.LEThread thread = new FLETestUtils.LEThread(peer, 1);
thread.start();
/*
* Start mock server 1
*/
mockServer();
thread.join(5000);
if (thread.isAlive()) {
Assert.fail("Threads didn't join");
}
}
示例8: testNoAuthLearnerConnectsToServerWithAuthNotRequired
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
* Test verifies that the No Auth enabled Learner is connecting to a No Auth
* Leader server. Learner should be able to establish a connection with
* Leader as auth is not required.
*/
@Test(timeout = 30000)
public void testNoAuthLearnerConnectsToServerWithAuthNotRequired()
throws Exception {
File testDataLearner = ClientBase.createTmpDir();
File tmpDir = File.createTempFile("test", ".dir", testDataLearner);
tmpDir.delete();
FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpDir, tmpDir);
QuorumPeer learnerPeer = createQuorumPeer(tmpDir, true, false, false,
"QuorumLearner", "QuorumServer", "");
SimpleLearner sl = new SimpleLearner(ftsl, learnerPeer);
File testDataLeader = ClientBase.createTmpDir();
tmpDir = File.createTempFile("test", ".dir", testDataLeader);
tmpDir.delete();
tmpDir.mkdir();
Leader leader = null;
QuorumPeer peer = createQuorumPeer(tmpDir, true, false, false, "QuorumLearner",
"QuorumServer",
QuorumAuth.QUORUM_KERBEROS_SERVICE_PRINCIPAL_DEFAULT_VALUE);
CountDownLatch learnerLatch = new CountDownLatch(1);
leader = createSimpleLeader(tmpDir, peer, learnerLatch);
peer.leader = leader;
startLearnerCnxAcceptorThread(leader);
LOG.info("Start establishing a connection with the Leader");
String hostname = getLeaderHostname(peer);
sl.connectToLeader(peer.getQuorumAddress(), hostname);
Assert.assertTrue("Leader should accept no auth learner connection",
learnerLatch.await(leader.self.tickTime * leader.self.initLimit + 1000,
TimeUnit.MILLISECONDS));
ClientBase.recursiveDelete(testDataLearner);
ClientBase.recursiveDelete(testDataLeader);
}
示例9: setup
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
@Before
public void setup() throws Exception {
File tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
SyncRequestProcessor.setSnapCount(100);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
servcnxnf = ServerCnxnFactory.createFactory(PORT, -1);
servcnxnf.startup(zks);
Assert.assertTrue("waiting for server being up ",
ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
zks.sessionTracker = new MySessionTracker();
}
示例10: testAuthLearnerConnectsToServerWithAuthNotRequired
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
* Test verifies that the Leader should authenticate the connecting learner
* quorumpeer. After the successful authentication it should add this
* learner to the learnerHandler list.
*/
@Test(timeout = 30000)
public void testAuthLearnerConnectsToServerWithAuthNotRequired()
throws Exception {
File testDataLearner = ClientBase.createTmpDir();
File tmpDir = File.createTempFile("test", ".dir", testDataLearner);
tmpDir.delete();
FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpDir, tmpDir);
QuorumPeer learnerPeer = createQuorumPeer(tmpDir, true, true, true,
"QuorumLearner", "QuorumServer",
QuorumAuth.QUORUM_KERBEROS_SERVICE_PRINCIPAL_DEFAULT_VALUE);
SimpleLearner sl = new SimpleLearner(ftsl, learnerPeer);
File testDataLeader = ClientBase.createTmpDir();
tmpDir = File.createTempFile("test", ".dir", testDataLeader);
tmpDir.delete();
tmpDir.mkdir();
Leader leader = null;
QuorumPeer peer = createQuorumPeer(tmpDir, true, true, false, "QuorumLearner",
"QuorumServer",
QuorumAuth.QUORUM_KERBEROS_SERVICE_PRINCIPAL_DEFAULT_VALUE);
CountDownLatch learnerLatch = new CountDownLatch(1);
leader = createSimpleLeader(tmpDir, peer, learnerLatch);
peer.leader = leader;
startLearnerCnxAcceptorThread(leader);
LOG.info("Start establishing a connection with the Leader");
String hostname = getLeaderHostname(peer);
sl.connectToLeader(peer.getQuorumAddress(), hostname);
// wait till leader socket soTimeout period
Assert.assertTrue("Leader should accept the auth learner connection",
learnerLatch.await(leader.self.tickTime * leader.self.initLimit + 1000,
TimeUnit.MILLISECONDS));
Assert.assertEquals("Failed to added the learner", 1,
leader.getLearners().size());
ClientBase.recursiveDelete(testDataLearner);
ClientBase.recursiveDelete(testDataLeader);
}
示例11: testPurgeTxnLogWithoutDataDir
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
* PurgeTxnLog is called with dataLogDir -n count This test case verify
* these values are parsed properly and functionality works fine
*/
@Test
public void testPurgeTxnLogWithoutDataDir()
throws Exception {
tmpDir = ClientBase.createTmpDir();
File dataDir = new File(tmpDir, "dataDir");
File dataLogDir = new File(tmpDir, "dataLogDir");
File dataDirVersion2 = new File(dataDir, "version-2");
dataDirVersion2.mkdirs();
File dataLogDirVersion2 = new File(dataLogDir, "version-2");
dataLogDirVersion2.mkdirs();
// create dummy log and transaction file
int totalFiles = 20;
// create transaction and snapshot files in data directory
for (int i = 0; i < totalFiles; i++) {
// simulate log file
File logFile = new File(dataLogDirVersion2, "log."
+ Long.toHexString(i));
logFile.createNewFile();
// simulate snapshot file
File snapFile = new File(dataLogDirVersion2, "snapshot."
+ Long.toHexString(i));
snapFile.createNewFile();
}
int numberOfFilesToKeep = 10;
// scenario where only three parameter are passed
String[] args = new String[] { dataLogDir.getAbsolutePath(), "-n",
Integer.toString(numberOfFilesToKeep) };
PurgeTxnLog.main(args);
assertEquals(numberOfFilesToKeep + numberOfFilesToKeep,
dataLogDirVersion2.listFiles().length);
ClientBase.recursiveDelete(tmpDir);
}
示例12: testPurgeWhenLogRollingInProgress
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
* Tests purge when logs are rolling or a new snapshot is created, then
* these newer files should alse be excluded in the current cycle.
*
* For frequent snapshotting, configured SnapCount to 30. There are three
* threads which will create 1000 znodes each and simultaneously do purge
* call
*/
@Test
public void testPurgeWhenLogRollingInProgress() throws Exception {
tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
SyncRequestProcessor.setSnapCount(30);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
Assert.assertTrue("waiting for server being up ",
ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
final ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
final CountDownLatch doPurge = new CountDownLatch(1);
final CountDownLatch purgeFinished = new CountDownLatch(1);
final AtomicBoolean opFailed = new AtomicBoolean(false);
new Thread() {
public void run() {
try {
doPurge.await(OP_TIMEOUT_IN_MILLIS / 2,
TimeUnit.MILLISECONDS);
PurgeTxnLog.purge(tmpDir, tmpDir, 3);
} catch (IOException ioe) {
LOG.error("Exception when purge", ioe);
opFailed.set(true);
} catch (InterruptedException ie) {
LOG.error("Exception when purge", ie);
opFailed.set(true);
} finally {
purgeFinished.countDown();
}
};
}.start();
final int thCount = 3;
List<String> znodes = manyClientOps(zk, doPurge, thCount,
"/invalidsnap");
Assert.assertTrue("Purging is not finished!", purgeFinished.await(
OP_TIMEOUT_IN_MILLIS, TimeUnit.MILLISECONDS));
Assert.assertFalse("Purging failed!", opFailed.get());
for (String znode : znodes) {
try {
zk.getData(znode, false, null);
} catch (Exception ke) {
LOG.error("Unexpected exception when visiting znode!", ke);
Assert.fail("Unexpected exception when visiting znode!");
}
}
zk.close();
f.shutdown();
zks.shutdown();
zks.getTxnLogFactory().close();
}
示例13: testClientConnectionRequestDuringStartupWithNettyServerCnxn
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
* Test case for
* {@link https://issues.apache.org/jira/browse/ZOOKEEPER-2383}.
*/
@Test(timeout = 30000)
public void testClientConnectionRequestDuringStartupWithNettyServerCnxn()
throws Exception {
tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
String originalServerCnxnFactory = System
.getProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY);
try {
System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY,
NettyServerCnxnFactory.class.getName());
startSimpleZKServer(startupDelayLatch);
SimpleZooKeeperServer simplezks = (SimpleZooKeeperServer) zks;
Assert.assertTrue(
"Failed to invoke zks#startup() method during server startup",
simplezks.waitForStartupInvocation(10));
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zkClient = new ZooKeeper(HOSTPORT,
ClientBase.CONNECTION_TIMEOUT, watcher);
Assert.assertFalse(
"Since server is not fully started, zks#createSession() shouldn't be invoked",
simplezks.waitForSessionCreation(5));
LOG.info(
"Decrements the count of the latch, so that server will proceed with startup");
startupDelayLatch.countDown();
Assert.assertTrue("waiting for server being up ", ClientBase
.waitForServerUp(HOSTPORT, ClientBase.CONNECTION_TIMEOUT));
Assert.assertTrue(
"Failed to invoke zks#createSession() method during client session creation",
simplezks.waitForSessionCreation(5));
watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
zkClient.close();
} finally {
// reset cnxn factory
if (originalServerCnxnFactory == null) {
System.clearProperty(
ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY);
} else {
System.setProperty(
ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY,
originalServerCnxnFactory);
}
}
}
示例14: testFindNRecentSnapshots
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
* Tests finding n recent snapshots from set of snapshots and data logs
*/
@Test
public void testFindNRecentSnapshots() throws Exception {
int nRecentSnap = 4; // n recent snap shots
int nRecentCount = 30;
int offset = 0;
tmpDir = ClientBase.createTmpDir();
File version2 = new File(tmpDir.toString(), "version-2");
Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
version2.mkdir());
// Test that with no snaps, findNRecentSnapshots returns empty list
FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
List<File> foundSnaps = txnLog.findNRecentSnapshots(1);
assertEquals(0, foundSnaps.size());
List<File> expectedNRecentSnapFiles = new ArrayList<File>();
int counter = offset + (2 * nRecentCount);
for (int i = 0; i < nRecentCount; i++) {
// simulate log file
File logFile = new File(version2 + "/log." + Long.toHexString(--counter));
Assert.assertTrue("Failed to create log File:" + logFile.toString(),
logFile.createNewFile());
// simulate snapshot file
File snapFile = new File(version2 + "/snapshot."
+ Long.toHexString(--counter));
Assert.assertTrue("Failed to create snap File:" + snapFile.toString(),
snapFile.createNewFile());
// add the n recent snap files for assertion
if(i < nRecentSnap){
expectedNRecentSnapFiles.add(snapFile);
}
}
// Test that when we ask for recent snaps we get the number we asked for and
// the files we expected
List<File> nRecentSnapFiles = txnLog.findNRecentSnapshots(nRecentSnap);
Assert.assertEquals("exactly 4 snapshots ", 4,
nRecentSnapFiles.size());
expectedNRecentSnapFiles.removeAll(nRecentSnapFiles);
Assert.assertEquals("Didn't get the recent snap files", 0,
expectedNRecentSnapFiles.size());
// Test that when asking for more snaps than we created, we still only get snaps
// not logs or anything else (per ZOOKEEPER-2420)
nRecentSnapFiles = txnLog.findNRecentSnapshots(nRecentCount + 5);
assertEquals(nRecentCount, nRecentSnapFiles.size());
for (File f: nRecentSnapFiles) {
Assert.assertTrue("findNRecentSnapshots() returned a non-snapshot: " + f.getPath(),
(Util.getZxidFromName(f.getName(), "snapshot") != -1));
}
txnLog.close();
}
示例15: testRaceBetweenSyncFlushAndZKShutdown
import org.apache.zookeeper.test.ClientBase; //导入方法依赖的package包/类
/**
* Test case to verify that ZooKeeper server is able to shutdown properly
* when there are pending request(s) in the RequestProcessor chain.
*
* {@link https://issues.apache.org/jira/browse/ZOOKEEPER-2347}
*/
@Test(timeout = 30000)
public void testRaceBetweenSyncFlushAndZKShutdown() throws Exception {
File tmpDir = ClientBase.createTmpDir();
File testDir = File.createTempFile("test", ".dir", tmpDir);
testDir.delete();
// Following are the sequence of steps to simulate the deadlock
// situation - SyncRequestProcessor#shutdown holds a lock and waits on
// FinalRequestProcessor to complete a pending operation, which in turn
// also needs the ZooKeeperServer lock
// 1. start zk server
FileTxnSnapLog ftsl = new FileTxnSnapLog(testDir, testDir);
final SimpleZooKeeperServer zkServer = new SimpleZooKeeperServer(ftsl);
zkServer.startup();
// 2. Wait for setting up request processor chain. At the end of setup,
// it will add a mock request into the chain
// 3. Also, waiting for FinalRequestProcessor to start processing request
zkServer.waitForFinalProcessRequest();
// 4. Above step ensures that there is a request in the processor chain.
// Now invoke shutdown, which will acquire zks lock
Thread shutdownThread = new Thread() {
public void run() {
zkServer.shutdown();
};
};
shutdownThread.start();
// 5. Wait for SyncRequestProcessor to trigger shutdown function.
// This is to ensure that zks lock is acquired
zkServer.waitForSyncReqProcessorShutdown();
// 6. Now resume FinalRequestProcessor which in turn call
// zks#decInProcess() function and tries to acquire zks lock.
// This results in deadlock
zkServer.resumeFinalProcessRequest();
// 7. Waiting to finish server shutdown. Testing that
// SyncRequestProcessor#shutdown holds a lock and waits on
// FinalRequestProcessor to complete a pending operation, which in turn
// also needs the ZooKeeperServer lock
shutdownThread.join();
}