Skip to content

Commit

Permalink
Port MasterFaultToleranceIntegrationTest to next
Browse files Browse the repository at this point in the history
  • Loading branch information
cc committed Sep 1, 2015
1 parent 446b34e commit 5a3acc6
Showing 1 changed file with 31 additions and 30 deletions.
Expand Up @@ -16,7 +16,7 @@
package tachyon.master.next;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.junit.After;
Expand All @@ -25,22 +25,25 @@
import org.junit.Ignore;
import org.junit.Test;

import com.google.common.collect.Lists;

import tachyon.Constants;
import tachyon.Pair;
import tachyon.TachyonURI;
import tachyon.client.TachyonFS;
import tachyon.client.TachyonFSTestUtils;
import tachyon.master.LocalTachyonClusterMultiMaster;
import tachyon.client.next.ClientOptions;
import tachyon.client.next.file.TachyonFS;
import tachyon.client.next.file.TachyonFSTestUtils;
import tachyon.client.next.file.TachyonFile;
import tachyon.conf.TachyonConf;
import tachyon.util.CommonUtils;
import tachyon.util.io.PathUtils;

/**
* Local Tachyon cluster with multiple master for unit tests.
*/
public class MasterFaultToleranceIntegrationTest {
private static final long WORKER_CAPACITY_BYTES = 10000;
private static final int BLOCK_SIZE = 30;
private static final int MASTERS = 5;

private tachyon.master.LocalTachyonClusterMultiMaster mLocalTachyonClusterMultiMaster = null;
private LocalTachyonClusterMultiMaster mLocalTachyonClusterMultiMaster = null;
private TachyonFS mTfs = null;

@After
Expand All @@ -51,57 +54,54 @@ public final void after() throws Exception {
@Before
public final void before() throws Exception {
mLocalTachyonClusterMultiMaster =
new LocalTachyonClusterMultiMaster(10000, MASTERS, BLOCK_SIZE);
new LocalTachyonClusterMultiMaster(WORKER_CAPACITY_BYTES, MASTERS, BLOCK_SIZE);
mLocalTachyonClusterMultiMaster.start();
mTfs = mLocalTachyonClusterMultiMaster.getClient();
}

/**
* Create 10 files in the folder
* Creates 10 files in the folder.
*
* @param folderName the folder name to create
* @param answer the results, the mapping from file id to file path
* @throws java.io.IOException
*/
private void faultTestDataCreation(TachyonURI folderName, List<Pair<Integer, TachyonURI>> answer)
private void faultTestDataCreation(TachyonURI folderName, List<Pair<Long, TachyonURI>> answer)
throws IOException {
TachyonFS tfs = mLocalTachyonClusterMultiMaster.getClient();
if (!tfs.exist(folderName)) {
tfs.mkdir(folderName);
answer.add(new Pair<Integer, TachyonURI>(tfs.getFileId(folderName), folderName));
}
mTfs.mkdirs(folderName);
answer.add(new Pair<Long, TachyonURI>(mTfs.open(folderName).getFileId(), folderName));

for (int k = 0; k < 10; k ++) {
TachyonURI path =
new TachyonURI(
folderName + TachyonURI.SEPARATOR + folderName.toString().substring(1) + k);
answer.add(new Pair<Integer, TachyonURI>(tfs.createFile(path), path));
new TachyonURI(PathUtils.concatPath(folderName, folderName.toString().substring(1), k));
mTfs.getOutStream(path, ClientOptions.defaults()).close();
answer.add(new Pair<Long, TachyonURI>(mTfs.open(path).getFileId(), path));
}
}

/**
* Tells if the results can match the answer
* Tells if the results can match the answer.
*
* @param answer the correct results
* @throws java.io.IOException
*/
private void faultTestDataCheck(List<Pair<Integer, TachyonURI>> answer) throws IOException {
TachyonFS tfs = mLocalTachyonClusterMultiMaster.getClient();
List<String> files = TachyonFSTestUtils.listFiles(tfs, TachyonURI.SEPARATOR);
private void faultTestDataCheck(List<Pair<Long, TachyonURI>> answer) throws IOException {
List<String> files = TachyonFSTestUtils.listFiles(mTfs, new TachyonURI(TachyonURI.SEPARATOR));
Collections.sort(files);
Assert.assertEquals(answer.size(), files.size());
for (int k = 0; k < answer.size(); k ++) {
Assert.assertEquals(answer.get(k).getSecond().toString(),
tfs.getFile(answer.get(k).getFirst()).getPath());
mTfs.getInfo(new TachyonFile(answer.get(k).getFirst())).getPath());
Assert.assertEquals(answer.get(k).getFirst().intValue(),
tfs.getFileId(answer.get(k).getSecond()));
mTfs.open(answer.get(k).getSecond()).getFileId());
}
}

@Ignore
@Test
public void faultTest() throws IOException {
int clients = 10;
List<Pair<Integer, TachyonURI>> answer = new ArrayList<Pair<Integer, TachyonURI>>();
List<Pair<Long, TachyonURI>> answer = Lists.newArrayList();
for (int k = 0; k < clients; k ++) {
faultTestDataCreation(new TachyonURI("/data" + k), answer);
}
Expand All @@ -127,13 +127,14 @@ public void faultTest() throws IOException {
@Test
public void getClientsTest() throws IOException {
int clients = 10;
mTfs.createFile(new TachyonURI("/0"), 1024);
for (int k = 1; k < clients; k ++) {
ClientOptions option = new ClientOptions.Builder(new TachyonConf()).setBlockSize(1024).build();
for (int k = 0; k < clients; k ++) {
TachyonFS tfs = mLocalTachyonClusterMultiMaster.getClient();
tfs.createFile(new TachyonURI(TachyonURI.SEPARATOR + k), 1024);
tfs.getOutStream(new TachyonURI(TachyonURI.SEPARATOR + k), option).close();
}
List<String> files = TachyonFSTestUtils.listFiles(mTfs, TachyonURI.SEPARATOR);
List<String> files = TachyonFSTestUtils.listFiles(mTfs, new TachyonURI(TachyonURI.SEPARATOR));
Assert.assertEquals(clients, files.size());
Collections.sort(files);
for (int k = 0; k < clients; k ++) {
Assert.assertEquals(TachyonURI.SEPARATOR + k, files.get(k));
}
Expand Down

0 comments on commit 5a3acc6

Please sign in to comment.