@SuppressWarnings("unchecked") @Test public void testRedirect() throws Exception { final String VOLUME_NAME = "testVolume"; final String FILE_PATH = "replicatedFile"; final int NUMBER_OF_REPLICAS = 2; Options options = new Options(); ClientImplementation client = (ClientImplementation) ClientFactory.createClient(ClientType.JAVA, dirServiceAddress, userCredentials, null, options); client.start(); client.createVolume(mrcServiceAddress, auth, userCredentials, VOLUME_NAME); Volume volume = client.openVolume(VOLUME_NAME, null, options); volume.setDefaultReplicationPolicy(userCredentials, "/", ReplicaUpdatePolicies.REPL_UPDATE_PC_WARONE, NUMBER_OF_REPLICAS, REPL_FLAG.REPL_FLAG_FULL_REPLICA.getNumber()); String replPolString = volume.getXAttr(userCredentials, "/", "xtreemfs.default_rp"); JSONString policy = new JSONString(replPolString); Map<String, Object> jsonMap = (Map<String, Object>) JSONParser.parseJSON(policy); assertEquals(ReplicaUpdatePolicies.REPL_UPDATE_PC_WARONE, jsonMap.get("update-policy").toString()); UUIDIterator mrcUUIDIterator = new UUIDIterator(); mrcUUIDIterator.addUUID(mrcServiceAddress); openRequest request = openRequest .newBuilder() .setVolumeName(VOLUME_NAME) .setPath(FILE_PATH) .setFlags( SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber() | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_TRUNC.getNumber() | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber()).setMode(0777) .setAttributes(0).build(); openResponse response = RPCCaller.<openRequest, openResponse> syncCall(SERVICES.MRC, userCredentials, auth, options, client, mrcUUIDIterator, true, request, new CallGenerator<openRequest, openResponse>() { @Override public RPCResponse<openResponse> executeCall(InetSocketAddress server, Auth authHeader, UserCredentials userCreds, openRequest input) throws IOException { return mrcServiceClient.open(server, authHeader, userCreds, input); } }); FileInfo fileInfo = new FileInfo((VolumeImplementation) volume, Helper.extractFileIdFromXcap(response .getCreds().getXcap()), FILE_PATH, false, response.getCreds().getXlocs(), Helper.generateVersion4UUID()); FileHandleImplementation fileHandle = fileInfo.createFileHandle(response.getCreds().getXcap(), false); String data = "Need a testfile? Why not (\\|)(+,,,+)(|/)?"; fileHandle.write(userCredentials, data.getBytes(), data.length(), 0); UUIDIterator uuidIterator = new UUIDIterator(); uuidIterator.addUUID(response.getCreds().getXlocs().getReplicas(1).getOsdUuids(0)); uuidIterator.addUUID(response.getCreds().getXlocs().getReplicas(0).getOsdUuids(0)); String overwriteData = "1111111111111111111111111111111111111111111111111111"; final ReusableBuffer overwriteBuf = ReusableBuffer.wrap(overwriteData.getBytes()); writeRequest.Builder writeReq = writeRequest.newBuilder(); writeReq.setFileCredentials(response.getCreds()); writeReq.setFileId(response.getCreds().getXcap().getFileId()); writeReq.setObjectNumber(0); writeReq.setObjectVersion(0); writeReq.setOffset(0); writeReq.setLeaseTimeout(0); ObjectData objectData = ObjectData.newBuilder().setChecksum(0).setInvalidChecksumOnOsd(false) .setZeroPadding(0).build(); writeReq.setObjectData(objectData); RPCCaller.<writeRequest, OSDWriteResponse> syncCall(SERVICES.OSD, userCredentials, auth, options, client, uuidIterator, false, writeReq.build(), new CallGenerator<writeRequest, OSDWriteResponse>() { @Override public RPCResponse<OSDWriteResponse> executeCall(InetSocketAddress server, Auth authHeader, UserCredentials userCreds, writeRequest input) throws IOException { return osdServiceClient.write(server, authHeader, userCreds, input, overwriteBuf); } }); byte[] readData = new byte[overwriteData.length()]; int readCount = fileHandle.read(userCredentials, readData, overwriteData.length(), 0); assertEquals(overwriteData.length(), readCount); for (int i = 0; i < overwriteData.length(); i++) { assertEquals(readData[i], overwriteData.getBytes()[i]); } }
protected static <C, R extends Message> R syncCall(SERVICES service, UserCredentials userCreds, Auth auth, Options options, UUIDResolver uuidResolver, UUIDIterator it, boolean uuidIteratorHasAddresses, C callRequest, CallGenerator<C, R> callGen) throws IOException, PosixErrorException, InternalServerErrorException, AddressToUUIDNotFoundException { return syncCall(service, userCreds, auth, options, uuidResolver, it, uuidIteratorHasAddresses, false, options.getMaxTries(), callRequest, null, callGen); }
RPCCaller { protected static <C, R extends Message> R syncCall(SERVICES service, UserCredentials userCreds, Auth auth, Options options, UUIDResolver uuidResolver, UUIDIterator it, boolean uuidIteratorHasAddresses, C callRequest, CallGenerator<C, R> callGen) throws IOException, PosixErrorException, InternalServerErrorException, AddressToUUIDNotFoundException { return syncCall(service, userCreds, auth, options, uuidResolver, it, uuidIteratorHasAddresses, false, options.getMaxTries(), callRequest, null, callGen); } }
RPCCaller { protected static <C, R extends Message> R syncCall(SERVICES service, UserCredentials userCreds, Auth auth, Options options, UUIDResolver uuidResolver, UUIDIterator it, boolean uuidIteratorHasAddresses, C callRequest, CallGenerator<C, R> callGen) throws IOException, PosixErrorException, InternalServerErrorException, AddressToUUIDNotFoundException { return syncCall(service, userCreds, auth, options, uuidResolver, it, uuidIteratorHasAddresses, false, options.getMaxTries(), callRequest, null, callGen); }  }
RPCCaller { protected static <C, R extends Message> R syncCall(SERVICES service, UserCredentials userCreds, Auth auth, Options options, UUIDResolver uuidResolver, UUIDIterator it, boolean uuidIteratorHasAddresses, C callRequest, CallGenerator<C, R> callGen) throws IOException, PosixErrorException, InternalServerErrorException, AddressToUUIDNotFoundException { return syncCall(service, userCreds, auth, options, uuidResolver, it, uuidIteratorHasAddresses, false, options.getMaxTries(), callRequest, null, callGen); }   }
RPCCaller { protected static <C, R extends Message> R syncCall(SERVICES service, UserCredentials userCreds, Auth auth, Options options, UUIDResolver uuidResolver, UUIDIterator it, boolean uuidIteratorHasAddresses, C callRequest, CallGenerator<C, R> callGen) throws IOException, PosixErrorException, InternalServerErrorException, AddressToUUIDNotFoundException { return syncCall(service, userCreds, auth, options, uuidResolver, it, uuidIteratorHasAddresses, false, options.getMaxTries(), callRequest, null, callGen); }    }