use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.
the class IgfsBackupFailoverSelfTest method testReadFailoverAfterStopMultipleNodes.
/**
* Checks correct data read *after* N-1 nodes are stopped.
*
* @throws Exception On error.
*/
public void testReadFailoverAfterStopMultipleNodes() throws Exception {
final IgfsImpl igfs0 = nodeDatas[0].igfsImpl;
clear(igfs0);
IgfsAbstractSelfTest.create(igfs0, paths(DIR, SUBDIR), null);
// Create files through the 0th node:
for (int f = 0; f < files; f++) {
final byte[] data = createChunk(fileSize, f);
createFile(igfs0, filePath(f), true, -1, /*block size unused*/
data);
}
// Check files:
for (int f = 0; f < files; f++) {
IgfsPath path = filePath(f);
byte[] data = createChunk(fileSize, f);
// Check through 0th node:
checkExist(igfs0, path);
checkFileContent(igfs0, path, data);
// Check the same file through other nodes:
for (int n = 1; n < numIgfsNodes; n++) {
checkExist(nodeDatas[n].igfsImpl, path);
checkFileContent(nodeDatas[n].igfsImpl, path, data);
}
}
// Now stop all the nodes but the 1st:
for (int n = 1; n < numIgfsNodes; n++) stopGrid(n);
// Check files again:
for (int f = 0; f < files; f++) {
IgfsPath path = filePath(f);
byte[] data = createChunk(fileSize, f);
// Check through 0th node:
checkExist(igfs0, path);
checkFileContent(igfs0, path, data);
}
}
use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.
the class IgfsBackupFailoverSelfTest method testReadFailoverWhileStoppingMultipleNodes.
/**
* Checks correct data read *while* N-1 nodes are being concurrently stopped.
*
* @throws Exception On error.
*/
public void testReadFailoverWhileStoppingMultipleNodes() throws Exception {
final IgfsImpl igfs0 = nodeDatas[0].igfsImpl;
clear(igfs0);
IgfsAbstractSelfTest.create(igfs0, paths(DIR, SUBDIR), null);
// Create files:
for (int f = 0; f < files; f++) {
final byte[] data = createChunk(fileSize, f);
createFile(igfs0, filePath(f), true, -1, /*block size unused*/
data);
}
// Check files:
for (int f = 0; f < files; f++) {
IgfsPath path = filePath(f);
byte[] data = createChunk(fileSize, f);
// Check through 1st node:
checkExist(igfs0, path);
checkFileContent(igfs0, path, data);
// Check the same file through other nodes:
for (int n = 1; n < numIgfsNodes; n++) {
checkExist(nodeDatas[n].igfsImpl, path);
checkFileContent(nodeDatas[n].igfsImpl, path, data);
}
}
final AtomicBoolean stop = new AtomicBoolean();
GridTestUtils.runMultiThreadedAsync(new Callable() {
@Override
public Object call() throws Exception {
// Some delay to ensure read is in progress.
Thread.sleep(1_000);
// Now stop all the nodes but the 1st:
for (int n = 1; n < numIgfsNodes; n++) {
stopGrid(n);
X.println("grid " + n + " stopped.");
}
Thread.sleep(1_000);
stop.set(true);
return null;
}
}, 1, "igfs-node-stopper");
// Read the files repeatedly, while the nodes are being stopped:
while (!stop.get()) {
// Check files while the nodes are being stopped:
for (int f = 0; f < files; f++) {
IgfsPath path = filePath(f);
byte[] data = createChunk(fileSize, f);
// Check through 1st node:
checkExist(igfs0, path);
checkFileContent(igfs0, path, data);
}
}
}
use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.
the class IgfsProcessorSelfTest method checkCreateAppendLongData.
/**
* @param chunkSize Chunk size.
* @param bufSize Buffer size.
* @param cnt Count.
* @throws Exception If failed.
*/
private void checkCreateAppendLongData(int chunkSize, int bufSize, int cnt) throws Exception {
IgfsPath path = new IgfsPath("/someFile");
byte[] buf = new byte[chunkSize];
for (int i = 0; i < buf.length; i++) buf[i] = (byte) (i * i);
IgfsOutputStream os = igfs.create(path, bufSize, true, null, 0, 1024, null);
try {
for (int i = 0; i < cnt; i++) os.write(buf);
os.flush();
} finally {
os.close();
}
os = igfs.append(path, chunkSize, false, null);
try {
for (int i = 0; i < cnt; i++) os.write(buf);
os.flush();
} finally {
os.close();
}
byte[] readBuf = new byte[chunkSize];
try (IgfsInputStream in = igfs.open(path)) {
long pos = 0;
for (int k = 0; k < 2 * cnt; k++) {
in.readFully(pos, readBuf);
for (int i = 0; i < readBuf.length; i++) assertEquals(buf[i], readBuf[i]);
pos += readBuf.length;
}
}
}
use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.
the class IgniteHadoopFileSystemClientSelfTest method testOutputStreamDeferredException.
/**
* Test output stream deferred exception (GG-4440).
*
* @throws Exception If failed.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testOutputStreamDeferredException() throws Exception {
final byte[] data = "test".getBytes();
try {
switchHandlerErrorFlag(true);
HadoopIgfs client = new HadoopIgfsOutProc("127.0.0.1", 10500, "igfs", LOG, null);
client.handshake(null);
IgfsPath path = new IgfsPath("/test1.file");
HadoopIgfsStreamDelegate delegate = client.create(path, true, false, 1, 1024, null);
final HadoopIgfsOutputStream igfsOut = new HadoopIgfsOutputStream(delegate, LOG, IgfsLogger.disabledLogger(), 0);
// This call should return fine as exception is thrown for the first time.
igfsOut.write(data);
U.sleep(500);
// This call should throw an IO exception.
GridTestUtils.assertThrows(null, new Callable<Object>() {
@Override
public Object call() throws Exception {
igfsOut.write(data);
return null;
}
}, IOException.class, "Failed to write data to server (test).");
} finally {
switchHandlerErrorFlag(false);
}
}
use of org.apache.ignite.igfs.IgfsPath in project ignite by apache.
the class HadoopIgfs20FileSystemAbstractSelfTest method testZeroReplicationFactor.
/**
* @throws Exception If failed.
*/
public void testZeroReplicationFactor() throws Exception {
// This test doesn't make sense for any mode except of PRIMARY.
if (mode == PRIMARY) {
Path igfsHome = new Path(primaryFsUri);
Path file = new Path(igfsHome, "someFile");
try (FSDataOutputStream out = fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault()), Options.CreateOpts.repFac((short) 1))) {
out.write(new byte[1024 * 1024]);
}
IgniteFileSystem igfs = grid(0).fileSystem("igfs");
IgfsPath filePath = new IgfsPath("/someFile");
IgfsFile fileInfo = igfs.info(filePath);
Collection<IgfsBlockLocation> locations = igfs.affinity(filePath, 0, fileInfo.length());
assertEquals(1, locations.size());
IgfsBlockLocation location = F.first(locations);
assertEquals(1, location.nodeIds().size());
}
}
Aggregations