1.JDK版本升级到1.6
2.测试代码按maven规范移入test目录
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
* <p>
|
||||
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
|
||||
* General Public License (LGPL).
|
||||
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
|
||||
*/
|
||||
|
||||
package org.csource.fastdfs.test;
|
||||
|
||||
import org.csource.fastdfs.DownloadCallback;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* DowloadCallback test
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.3
|
||||
*/
|
||||
public class DownloadFileWriter implements DownloadCallback {
|
||||
private String filename;
|
||||
private FileOutputStream out = null;
|
||||
private long current_bytes = 0;
|
||||
|
||||
public DownloadFileWriter(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public int recv(long file_size, byte[] data, int bytes) {
|
||||
try {
|
||||
if (this.out == null) {
|
||||
this.out = new FileOutputStream(this.filename);
|
||||
}
|
||||
|
||||
this.out.write(data, 0, bytes);
|
||||
this.current_bytes += bytes;
|
||||
|
||||
if (this.current_bytes == file_size) {
|
||||
this.out.close();
|
||||
this.out = null;
|
||||
this.current_bytes = 0;
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
if (this.out != null) {
|
||||
this.out.close();
|
||||
this.out = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,203 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
* <p>
|
||||
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
|
||||
* General Public License (LGPL).
|
||||
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
|
||||
**/
|
||||
|
||||
package org.csource.fastdfs.test;
|
||||
|
||||
import org.csource.fastdfs.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* load test class
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.20
|
||||
*/
|
||||
public class Monitor {
|
||||
private Monitor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* entry point
|
||||
*
|
||||
* @param args comand arguments
|
||||
* <ul><li>args[0]: config filename</li></ul>
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
if (args.length < 1) {
|
||||
System.out.println("Error: Must have 1 parameter: config filename");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("java.version=" + System.getProperty("java.version"));
|
||||
|
||||
try {
|
||||
ClientGlobal.init(args[0]);
|
||||
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
|
||||
System.out.println("charset=" + ClientGlobal.g_charset);
|
||||
|
||||
TrackerClient tracker = new TrackerClient();
|
||||
|
||||
/*
|
||||
System.out.println("delete storage return: " + tracker.deleteStorage("group1", "192.168.0.192"));
|
||||
System.out.println("delete storage errno: " + tracker.getErrorCode());
|
||||
*/
|
||||
|
||||
TrackerServer trackerServer = tracker.getConnection();
|
||||
if (trackerServer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int count;
|
||||
StructGroupStat[] groupStats = tracker.listGroups(trackerServer);
|
||||
if (groupStats == null) {
|
||||
System.out.println("");
|
||||
System.out.println("ERROR! list groups error, error no: " + tracker.getErrorCode());
|
||||
System.out.println("");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("group count: " + groupStats.length);
|
||||
|
||||
count = 0;
|
||||
for (StructGroupStat groupStat : groupStats) {
|
||||
count++;
|
||||
System.out.println("Group " + count + ":");
|
||||
System.out.println("group name = " + groupStat.getGroupName());
|
||||
System.out.println("disk total space = " + groupStat.getTotalMB() + "MB");
|
||||
System.out.println("disk free space = " + groupStat.getFreeMB() + " MB");
|
||||
System.out.println("trunk free space = " + groupStat.getTrunkFreeMB() + " MB");
|
||||
System.out.println("storage server count = " + groupStat.getStorageCount());
|
||||
System.out.println("active server count = " + groupStat.getActiveCount());
|
||||
System.out.println("storage server port = " + groupStat.getStoragePort());
|
||||
System.out.println("storage HTTP port = " + groupStat.getStorageHttpPort());
|
||||
System.out.println("store path count = " + groupStat.getStorePathCount());
|
||||
System.out.println("subdir count per path = " + groupStat.getSubdirCountPerPath());
|
||||
System.out.println("current write server index = " + groupStat.getCurrentWriteServer());
|
||||
System.out.println("current trunk file id = " + groupStat.getCurrentTrunkFileId());
|
||||
|
||||
StructStorageStat[] storageStats = tracker.listStorages(trackerServer, groupStat.getGroupName());
|
||||
if (storageStats == null) {
|
||||
System.out.println("");
|
||||
System.out.println("ERROR! list storage error, error no: " + tracker.getErrorCode());
|
||||
System.out.println("");
|
||||
break;
|
||||
}
|
||||
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
int stroageCount = 0;
|
||||
for (StructStorageStat storageStat : storageStats) {
|
||||
stroageCount++;
|
||||
System.out.println("\tStorage " + stroageCount + ":");
|
||||
System.out.println("\t\tstorage id = " + storageStat.getId());
|
||||
System.out.println("\t\tip_addr = " + storageStat.getIpAddr() + " " + ProtoCommon.getStorageStatusCaption(storageStat.getStatus()));
|
||||
System.out.println("\t\thttp domain = " + storageStat.getDomainName());
|
||||
System.out.println("\t\tversion = " + storageStat.getVersion());
|
||||
System.out.println("\t\tjoin time = " + df.format(storageStat.getJoinTime()));
|
||||
System.out.println("\t\tup time = " + (storageStat.getUpTime().getTime() == 0 ? "" : df.format(storageStat.getUpTime())));
|
||||
System.out.println("\t\ttotal storage = " + storageStat.getTotalMB() + "MB");
|
||||
System.out.println("\t\tfree storage = " + storageStat.getFreeMB() + "MB");
|
||||
System.out.println("\t\tupload priority = " + storageStat.getUploadPriority());
|
||||
System.out.println("\t\tstore_path_count = " + storageStat.getStorePathCount());
|
||||
System.out.println("\t\tsubdir_count_per_path = " + storageStat.getSubdirCountPerPath());
|
||||
System.out.println("\t\tstorage_port = " + storageStat.getStoragePort());
|
||||
System.out.println("\t\tstorage_http_port = " + storageStat.getStorageHttpPort());
|
||||
System.out.println("\t\tcurrent_write_path = " + storageStat.getCurrentWritePath());
|
||||
System.out.println("\t\tsource ip_addr = " + storageStat.getSrcIpAddr());
|
||||
System.out.println("\t\tif_trunk_server = " + storageStat.isTrunkServer());
|
||||
System.out.println("\t\tconntion.alloc_count = " + storageStat.getConnectionAllocCount());
|
||||
System.out.println("\t\tconntion.current_count = " + storageStat.getConnectionCurrentCount());
|
||||
System.out.println("\t\tconntion.max_count = " + storageStat.getConnectionMaxCount());
|
||||
System.out.println("\t\ttotal_upload_count = " + storageStat.getTotalUploadCount());
|
||||
System.out.println("\t\tsuccess_upload_count = " + storageStat.getSuccessUploadCount());
|
||||
System.out.println("\t\ttotal_append_count = " + storageStat.getTotalAppendCount());
|
||||
System.out.println("\t\tsuccess_append_count = " + storageStat.getSuccessAppendCount());
|
||||
System.out.println("\t\ttotal_modify_count = " + storageStat.getTotalModifyCount());
|
||||
System.out.println("\t\tsuccess_modify_count = " + storageStat.getSuccessModifyCount());
|
||||
System.out.println("\t\ttotal_truncate_count = " + storageStat.getTotalTruncateCount());
|
||||
System.out.println("\t\tsuccess_truncate_count = " + storageStat.getSuccessTruncateCount());
|
||||
System.out.println("\t\ttotal_set_meta_count = " + storageStat.getTotalSetMetaCount());
|
||||
System.out.println("\t\tsuccess_set_meta_count = " + storageStat.getSuccessSetMetaCount());
|
||||
System.out.println("\t\ttotal_delete_count = " + storageStat.getTotalDeleteCount());
|
||||
System.out.println("\t\tsuccess_delete_count = " + storageStat.getSuccessDeleteCount());
|
||||
System.out.println("\t\ttotal_download_count = " + storageStat.getTotalDownloadCount());
|
||||
System.out.println("\t\tsuccess_download_count = " + storageStat.getSuccessDownloadCount());
|
||||
System.out.println("\t\ttotal_get_meta_count = " + storageStat.getTotalGetMetaCount());
|
||||
System.out.println("\t\tsuccess_get_meta_count = " + storageStat.getSuccessGetMetaCount());
|
||||
System.out.println("\t\ttotal_create_link_count = " + storageStat.getTotalCreateLinkCount());
|
||||
System.out.println("\t\tsuccess_create_link_count = " + storageStat.getSuccessCreateLinkCount());
|
||||
System.out.println("\t\ttotal_delete_link_count = " + storageStat.getTotalDeleteLinkCount());
|
||||
System.out.println("\t\tsuccess_delete_link_count = " + storageStat.getSuccessDeleteLinkCount());
|
||||
System.out.println("\t\ttotal_upload_bytes = " + storageStat.getTotalUploadBytes());
|
||||
System.out.println("\t\tsuccess_upload_bytes = " + storageStat.getSuccessUploadBytes());
|
||||
System.out.println("\t\ttotal_append_bytes = " + storageStat.getTotalAppendBytes());
|
||||
System.out.println("\t\tsuccess_append_bytes = " + storageStat.getSuccessAppendBytes());
|
||||
System.out.println("\t\ttotal_modify_bytes = " + storageStat.getTotalModifyBytes());
|
||||
System.out.println("\t\tsuccess_modify_bytes = " + storageStat.getSuccessModifyBytes());
|
||||
System.out.println("\t\ttotal_download_bytes = " + storageStat.getTotalDownloadloadBytes());
|
||||
System.out.println("\t\tsuccess_download_bytes = " + storageStat.getSuccessDownloadloadBytes());
|
||||
System.out.println("\t\ttotal_sync_in_bytes = " + storageStat.getTotalSyncInBytes());
|
||||
System.out.println("\t\tsuccess_sync_in_bytes = " + storageStat.getSuccessSyncInBytes());
|
||||
System.out.println("\t\ttotal_sync_out_bytes = " + storageStat.getTotalSyncOutBytes());
|
||||
System.out.println("\t\tsuccess_sync_out_bytes = " + storageStat.getSuccessSyncOutBytes());
|
||||
System.out.println("\t\ttotal_file_open_count = " + storageStat.getTotalFileOpenCount());
|
||||
System.out.println("\t\tsuccess_file_open_count = " + storageStat.getSuccessFileOpenCount());
|
||||
System.out.println("\t\ttotal_file_read_count = " + storageStat.getTotalFileReadCount());
|
||||
System.out.println("\t\tsuccess_file_read_count = " + storageStat.getSuccessFileReadCount());
|
||||
System.out.println("\t\ttotal_file_write_count = " + storageStat.getTotalFileWriteCount());
|
||||
System.out.println("\t\tsuccess_file_write_count = " + storageStat.getSuccessFileWriteCount());
|
||||
System.out.println("\t\tlast_heart_beat_time = " + df.format(storageStat.getLastHeartBeatTime()));
|
||||
System.out.println("\t\tlast_source_update = " + df.format(storageStat.getLastSourceUpdate()));
|
||||
System.out.println("\t\tlast_sync_update = " + df.format(storageStat.getLastSyncUpdate()));
|
||||
System.out.println("\t\tlast_synced_timestamp = " + df.format(storageStat.getLastSyncedTimestamp()) + getSyncedDelayString(storageStats, storageStat));
|
||||
}
|
||||
}
|
||||
|
||||
trackerServer.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static String getSyncedDelayString(StructStorageStat[] storageStats, StructStorageStat currentStorageStat) {
|
||||
long maxLastSourceUpdate = 0;
|
||||
for (StructStorageStat storageStat : storageStats) {
|
||||
if (storageStat != currentStorageStat && storageStat.getLastSourceUpdate().getTime() > maxLastSourceUpdate) {
|
||||
maxLastSourceUpdate = storageStat.getLastSourceUpdate().getTime();
|
||||
}
|
||||
}
|
||||
|
||||
if (maxLastSourceUpdate == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (currentStorageStat.getLastSyncedTimestamp().getTime() == 0) {
|
||||
return " (never synced)";
|
||||
}
|
||||
|
||||
int delaySeconds = (int) ((maxLastSourceUpdate - currentStorageStat.getLastSyncedTimestamp().getTime()) / 1000);
|
||||
int day = delaySeconds / (24 * 3600);
|
||||
int remainSeconds = delaySeconds % (24 * 3600);
|
||||
int hour = remainSeconds / 3600;
|
||||
remainSeconds %= 3600;
|
||||
int minute = remainSeconds / 60;
|
||||
int second = remainSeconds % 60;
|
||||
String delayTimeStr;
|
||||
if (day != 0) {
|
||||
delayTimeStr = String.format("%1$d days %2$02dh:%3$02dm:%4$02ds", day, hour, minute, second);
|
||||
} else if (hour != 0) {
|
||||
delayTimeStr = String.format("%1$02dh:%2$02dm:%3$02ds", hour, minute, second);
|
||||
} else if (minute != 0) {
|
||||
delayTimeStr = String.format("%1$02dm:%2$02ds", minute, second);
|
||||
} else {
|
||||
delayTimeStr = String.format("%1$ds", second);
|
||||
}
|
||||
|
||||
return " (" + delayTimeStr + " delay)";
|
||||
}
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
* <p>
|
||||
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
|
||||
* General Public License (LGPL).
|
||||
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
|
||||
**/
|
||||
|
||||
package org.csource.fastdfs.test;
|
||||
|
||||
import org.csource.common.NameValuePair;
|
||||
import org.csource.fastdfs.*;
|
||||
|
||||
/**
|
||||
* client test
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.18
|
||||
*/
|
||||
public class Test {
|
||||
private Test() {
|
||||
}
|
||||
|
||||
/**
|
||||
* entry point
|
||||
*
|
||||
* @param args comand arguments
|
||||
* <ul><li>args[0]: config filename</li></ul>
|
||||
* <ul><li>args[1]: local filename to upload</li></ul>
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
if (args.length < 2) {
|
||||
System.out.println("Error: Must have 2 parameters, one is config filename, "
|
||||
+ "the other is the local filename to upload");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("java.version=" + System.getProperty("java.version"));
|
||||
|
||||
String conf_filename = args[0];
|
||||
String local_filename = args[1];
|
||||
|
||||
try {
|
||||
ClientGlobal.init(conf_filename);
|
||||
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
|
||||
System.out.println("charset=" + ClientGlobal.g_charset);
|
||||
|
||||
TrackerClient tracker = new TrackerClient();
|
||||
TrackerServer trackerServer = tracker.getConnection();
|
||||
StorageServer storageServer = null;
|
||||
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
|
||||
|
||||
NameValuePair[] metaList = new NameValuePair[1];
|
||||
metaList[0] = new NameValuePair("fileName", local_filename);
|
||||
String fileId = client.upload_file1(local_filename, null, metaList);
|
||||
System.out.println("upload success. file id is: " + fileId);
|
||||
|
||||
int i = 0;
|
||||
while (i++ < 10) {
|
||||
byte[] result = client.download_file1(fileId);
|
||||
System.out.println(i + ", download result is: " + result.length);
|
||||
}
|
||||
|
||||
trackerServer.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
package org.csource.fastdfs.test;
|
||||
|
||||
import org.csource.common.NameValuePair;
|
||||
import org.csource.fastdfs.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class Test1 {
|
||||
public static void main(String args[]) {
|
||||
try {
|
||||
ClientGlobal.init("fdfs_client.conf");
|
||||
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
|
||||
System.out.println("charset=" + ClientGlobal.g_charset);
|
||||
|
||||
TrackerGroup tg = new TrackerGroup(new InetSocketAddress[]{new InetSocketAddress("10.0.11.243", 22122)});
|
||||
TrackerClient tc = new TrackerClient(tg);
|
||||
|
||||
TrackerServer ts = tc.getConnection();
|
||||
if (ts == null) {
|
||||
System.out.println("getConnection return null");
|
||||
return;
|
||||
}
|
||||
|
||||
StorageServer ss = tc.getStoreStorage(ts);
|
||||
if (ss == null) {
|
||||
System.out.println("getStoreStorage return null");
|
||||
}
|
||||
|
||||
StorageClient1 sc1 = new StorageClient1(ts, ss);
|
||||
|
||||
NameValuePair[] meta_list = null; //new NameValuePair[0];
|
||||
String item;
|
||||
String fileid;
|
||||
if (System.getProperty("os.name").equalsIgnoreCase("windows")) {
|
||||
item = "c:/windows/system32/notepad.exe";
|
||||
fileid = sc1.upload_file1(item, "exe", meta_list);
|
||||
} else {
|
||||
item = "/etc/hosts";
|
||||
fileid = sc1.upload_file1(item, "", meta_list);
|
||||
}
|
||||
|
||||
System.out.println("Upload local file " + item + " ok, fileid=" + fileid);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,302 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
* <p>
|
||||
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
|
||||
* General Public License (LGPL).
|
||||
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
|
||||
**/
|
||||
|
||||
package org.csource.fastdfs.test;
|
||||
|
||||
import org.csource.common.NameValuePair;
|
||||
import org.csource.fastdfs.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* client test
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.20
|
||||
*/
|
||||
public class TestAppender {
|
||||
private TestAppender() {
|
||||
}
|
||||
|
||||
/**
|
||||
* entry point
|
||||
*
|
||||
* @param args comand arguments
|
||||
* <ul><li>args[0]: config filename</li></ul>
|
||||
* <ul><li>args[1]: local filename to upload</li></ul>
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
if (args.length < 2) {
|
||||
System.out.println("Error: Must have 2 parameters, one is config filename, "
|
||||
+ "the other is the local filename to upload");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("java.version=" + System.getProperty("java.version"));
|
||||
|
||||
String conf_filename = args[0];
|
||||
String local_filename = args[1];
|
||||
|
||||
try {
|
||||
ClientGlobal.init(conf_filename);
|
||||
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
|
||||
System.out.println("charset=" + ClientGlobal.g_charset);
|
||||
|
||||
long startTime;
|
||||
String group_name;
|
||||
String remote_filename;
|
||||
ServerInfo[] servers;
|
||||
TrackerClient tracker = new TrackerClient();
|
||||
TrackerServer trackerServer = tracker.getConnection();
|
||||
|
||||
StorageServer storageServer = null;
|
||||
|
||||
/*
|
||||
storageServer = tracker.getStoreStorage(trackerServer);
|
||||
if (storageServer == null)
|
||||
{
|
||||
System.out.println("getStoreStorage fail, error code: " + tracker.getErrorCode());
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
StorageClient client = new StorageClient(trackerServer, storageServer);
|
||||
byte[] file_buff;
|
||||
NameValuePair[] meta_list;
|
||||
String[] results;
|
||||
String appender_filename;
|
||||
String file_ext_name;
|
||||
int errno;
|
||||
|
||||
meta_list = new NameValuePair[4];
|
||||
meta_list[0] = new NameValuePair("width", "800");
|
||||
meta_list[1] = new NameValuePair("heigth", "600");
|
||||
meta_list[2] = new NameValuePair("bgcolor", "#FFFFFF");
|
||||
meta_list[3] = new NameValuePair("author", "Mike");
|
||||
|
||||
file_buff = "this is a test".getBytes(ClientGlobal.g_charset);
|
||||
System.out.println("file length: " + file_buff.length);
|
||||
|
||||
group_name = null;
|
||||
StorageServer[] storageServers = tracker.getStoreStorages(trackerServer, group_name);
|
||||
if (storageServers == null) {
|
||||
System.err.println("get store storage servers fail, error code: " + tracker.getErrorCode());
|
||||
} else {
|
||||
System.err.println("store storage servers count: " + storageServers.length);
|
||||
for (int k = 0; k < storageServers.length; k++) {
|
||||
System.err.println((k + 1) + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort());
|
||||
}
|
||||
System.err.println("");
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
results = client.upload_appender_file(file_buff, "txt", meta_list);
|
||||
System.out.println("upload_appender_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
|
||||
/*
|
||||
group_name = "";
|
||||
results = client.upload_appender_file(group_name, file_buff, "txt", meta_list);
|
||||
*/
|
||||
if (results == null) {
|
||||
System.err.println("upload file fail, error code: " + client.getErrorCode());
|
||||
return;
|
||||
} else {
|
||||
group_name = results[0];
|
||||
remote_filename = results[1];
|
||||
System.err.println("group_name: " + group_name + ", remote_filename: " + remote_filename);
|
||||
System.err.println(client.get_file_info(group_name, remote_filename));
|
||||
|
||||
servers = tracker.getFetchStorages(trackerServer, group_name, remote_filename);
|
||||
if (servers == null) {
|
||||
System.err.println("get storage servers fail, error code: " + tracker.getErrorCode());
|
||||
} else {
|
||||
System.err.println("storage servers count: " + servers.length);
|
||||
for (int k = 0; k < servers.length; k++) {
|
||||
System.err.println((k + 1) + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort());
|
||||
}
|
||||
System.err.println("");
|
||||
}
|
||||
|
||||
meta_list = new NameValuePair[4];
|
||||
meta_list[0] = new NameValuePair("width", "1024");
|
||||
meta_list[1] = new NameValuePair("heigth", "768");
|
||||
meta_list[2] = new NameValuePair("bgcolor", "#000000");
|
||||
meta_list[3] = new NameValuePair("title", "Untitle");
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.set_metadata(group_name, remote_filename, meta_list, ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE);
|
||||
System.out.println("set_metadata time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println("set_metadata success");
|
||||
} else {
|
||||
System.err.println("set_metadata fail, error no: " + errno);
|
||||
}
|
||||
|
||||
meta_list = client.get_metadata(group_name, remote_filename);
|
||||
if (meta_list != null) {
|
||||
for (int i = 0; i < meta_list.length; i++) {
|
||||
System.out.println(meta_list[i].getName() + " " + meta_list[i].getValue());
|
||||
}
|
||||
}
|
||||
|
||||
//Thread.sleep(30000);
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
file_buff = client.download_file(group_name, remote_filename);
|
||||
System.out.println("download_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
|
||||
if (file_buff != null) {
|
||||
System.out.println("file length:" + file_buff.length);
|
||||
System.out.println((new String(file_buff)));
|
||||
}
|
||||
|
||||
file_buff = "this is a slave buff".getBytes(ClientGlobal.g_charset);
|
||||
appender_filename = remote_filename;
|
||||
file_ext_name = "txt";
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.append_file(group_name, appender_filename, file_buff);
|
||||
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println(client.get_file_info(group_name, appender_filename));
|
||||
} else {
|
||||
System.err.println("append file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.delete_file(group_name, remote_filename);
|
||||
System.out.println("delete_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println("Delete file success");
|
||||
} else {
|
||||
System.err.println("Delete file fail, error no: " + errno);
|
||||
}
|
||||
}
|
||||
|
||||
results = client.upload_appender_file(local_filename, null, meta_list);
|
||||
if (results != null) {
|
||||
String file_id;
|
||||
int ts;
|
||||
String token;
|
||||
String file_url;
|
||||
InetSocketAddress inetSockAddr;
|
||||
|
||||
group_name = results[0];
|
||||
remote_filename = results[1];
|
||||
file_id = group_name + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remote_filename;
|
||||
|
||||
inetSockAddr = trackerServer.getInetSocketAddress();
|
||||
file_url = "http://" + inetSockAddr.getAddress().getHostAddress();
|
||||
if (ClientGlobal.g_tracker_http_port != 80) {
|
||||
file_url += ":" + ClientGlobal.g_tracker_http_port;
|
||||
}
|
||||
file_url += "/" + file_id;
|
||||
if (ClientGlobal.g_anti_steal_token) {
|
||||
ts = (int) (System.currentTimeMillis() / 1000);
|
||||
token = ProtoCommon.getToken(file_id, ts, ClientGlobal.g_secret_key);
|
||||
file_url += "?token=" + token + "&ts=" + ts;
|
||||
}
|
||||
|
||||
System.err.println("group_name: " + group_name + ", remote_filename: " + remote_filename);
|
||||
System.err.println(client.get_file_info(group_name, remote_filename));
|
||||
System.err.println("file url: " + file_url);
|
||||
|
||||
errno = client.download_file(group_name, remote_filename, 0, 0, "c:\\" + remote_filename.replaceAll("/", "_"));
|
||||
if (errno == 0) {
|
||||
System.err.println("Download file success");
|
||||
} else {
|
||||
System.err.println("Download file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
errno = client.download_file(group_name, remote_filename, 0, 0, new DownloadFileWriter("c:\\" + remote_filename.replaceAll("/", "-")));
|
||||
if (errno == 0) {
|
||||
System.err.println("Download file success");
|
||||
} else {
|
||||
System.err.println("Download file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
appender_filename = remote_filename;
|
||||
file_ext_name = null;
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.append_file(group_name, appender_filename, local_filename);
|
||||
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println(client.get_file_info(group_name, appender_filename));
|
||||
} else {
|
||||
System.err.println("append file fail, error no: " + errno);
|
||||
}
|
||||
}
|
||||
|
||||
File f;
|
||||
f = new File(local_filename);
|
||||
int nPos = local_filename.lastIndexOf('.');
|
||||
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) {
|
||||
file_ext_name = local_filename.substring(nPos + 1);
|
||||
} else {
|
||||
file_ext_name = null;
|
||||
}
|
||||
|
||||
results = client.upload_appender_file(null, f.length(),
|
||||
new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
|
||||
if (results != null) {
|
||||
group_name = results[0];
|
||||
remote_filename = results[1];
|
||||
|
||||
System.out.println("group name: " + group_name + ", remote filename: " + remote_filename);
|
||||
System.out.println(client.get_file_info(group_name, remote_filename));
|
||||
|
||||
appender_filename = remote_filename;
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.append_file(group_name, appender_filename, f.length(), new UploadLocalFileSender(local_filename));
|
||||
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println(client.get_file_info(group_name, appender_filename));
|
||||
} else {
|
||||
System.err.println("append file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.modify_file(group_name, appender_filename, 0, f.length(), new UploadLocalFileSender(local_filename));
|
||||
System.out.println("modify_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println(client.get_file_info(group_name, appender_filename));
|
||||
} else {
|
||||
System.err.println("modify file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.truncate_file(group_name, appender_filename);
|
||||
System.out.println("truncate_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println(client.get_file_info(group_name, appender_filename));
|
||||
} else {
|
||||
System.err.println("truncate file fail, error no: " + errno);
|
||||
}
|
||||
} else {
|
||||
System.err.println("Upload file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
storageServer = tracker.getFetchStorage(trackerServer, group_name, remote_filename);
|
||||
if (storageServer == null) {
|
||||
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
|
||||
return;
|
||||
}
|
||||
/* for test only */
|
||||
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
|
||||
|
||||
storageServer.close();
|
||||
|
||||
/* for test only */
|
||||
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
|
||||
|
||||
trackerServer.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,282 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
* <p>
|
||||
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
|
||||
* General Public License (LGPL).
|
||||
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
|
||||
**/
|
||||
|
||||
package org.csource.fastdfs.test;
|
||||
|
||||
import org.csource.common.NameValuePair;
|
||||
import org.csource.fastdfs.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* client test
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.20
|
||||
*/
|
||||
public class TestAppender1 {
|
||||
private TestAppender1() {
|
||||
}
|
||||
|
||||
/**
|
||||
* entry point
|
||||
*
|
||||
* @param args comand arguments
|
||||
* <ul><li>args[0]: config filename</li></ul>
|
||||
* <ul><li>args[1]: local filename to upload</li></ul>
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
if (args.length < 2) {
|
||||
System.out.println("Error: Must have 2 parameters, one is config filename, "
|
||||
+ "the other is the local filename to upload");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("java.version=" + System.getProperty("java.version"));
|
||||
|
||||
String conf_filename = args[0];
|
||||
String local_filename = args[1];
|
||||
|
||||
try {
|
||||
ClientGlobal.init(conf_filename);
|
||||
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
|
||||
System.out.println("charset=" + ClientGlobal.g_charset);
|
||||
|
||||
long startTime;
|
||||
ServerInfo[] servers;
|
||||
TrackerClient tracker = new TrackerClient();
|
||||
TrackerServer trackerServer = tracker.getConnection();
|
||||
|
||||
StorageServer storageServer = null;
|
||||
|
||||
/*
|
||||
storageServer = tracker.getStoreStorage(trackerServer);
|
||||
if (storageServer == null)
|
||||
{
|
||||
System.out.println("getStoreStorage fail, error code: " + tracker.getErrorCode());
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
|
||||
byte[] file_buff;
|
||||
NameValuePair[] meta_list;
|
||||
String group_name;
|
||||
String appender_file_id;
|
||||
String file_ext_name;
|
||||
int errno;
|
||||
|
||||
meta_list = new NameValuePair[4];
|
||||
meta_list[0] = new NameValuePair("width", "800");
|
||||
meta_list[1] = new NameValuePair("heigth", "600");
|
||||
meta_list[2] = new NameValuePair("bgcolor", "#FFFFFF");
|
||||
meta_list[3] = new NameValuePair("author", "Mike");
|
||||
|
||||
file_buff = "this is a test".getBytes(ClientGlobal.g_charset);
|
||||
System.out.println("file length: " + file_buff.length);
|
||||
|
||||
group_name = null;
|
||||
StorageServer[] storageServers = tracker.getStoreStorages(trackerServer, group_name);
|
||||
if (storageServers == null) {
|
||||
System.err.println("get store storage servers fail, error code: " + tracker.getErrorCode());
|
||||
} else {
|
||||
System.err.println("store storage servers count: " + storageServers.length);
|
||||
for (int k = 0; k < storageServers.length; k++) {
|
||||
System.err.println((k + 1) + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort());
|
||||
}
|
||||
System.err.println("");
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
appender_file_id = client.upload_appender_file1(file_buff, "txt", meta_list);
|
||||
System.out.println("upload_appender_file1 time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
|
||||
/*
|
||||
group_name = "";
|
||||
appender_file_id = client.upload_appender_file1(group_name, file_buff, "txt", meta_list);
|
||||
*/
|
||||
if (appender_file_id == null) {
|
||||
System.err.println("upload file fail, error code: " + client.getErrorCode());
|
||||
return;
|
||||
} else {
|
||||
System.err.println(client.get_file_info1(appender_file_id));
|
||||
|
||||
servers = tracker.getFetchStorages1(trackerServer, appender_file_id);
|
||||
if (servers == null) {
|
||||
System.err.println("get storage servers fail, error code: " + tracker.getErrorCode());
|
||||
} else {
|
||||
System.err.println("storage servers count: " + servers.length);
|
||||
for (int k = 0; k < servers.length; k++) {
|
||||
System.err.println((k + 1) + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort());
|
||||
}
|
||||
System.err.println("");
|
||||
}
|
||||
|
||||
meta_list = new NameValuePair[4];
|
||||
meta_list[0] = new NameValuePair("width", "1024");
|
||||
meta_list[1] = new NameValuePair("heigth", "768");
|
||||
meta_list[2] = new NameValuePair("bgcolor", "#000000");
|
||||
meta_list[3] = new NameValuePair("title", "Untitle");
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.set_metadata1(appender_file_id, meta_list, ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE);
|
||||
System.out.println("set_metadata time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println("set_metadata success");
|
||||
} else {
|
||||
System.err.println("set_metadata fail, error no: " + errno);
|
||||
}
|
||||
|
||||
meta_list = client.get_metadata1(appender_file_id);
|
||||
if (meta_list != null) {
|
||||
for (int i = 0; i < meta_list.length; i++) {
|
||||
System.out.println(meta_list[i].getName() + " " + meta_list[i].getValue());
|
||||
}
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
file_buff = client.download_file1(appender_file_id);
|
||||
System.out.println("download_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
|
||||
if (file_buff != null) {
|
||||
System.out.println("file length:" + file_buff.length);
|
||||
System.out.println((new String(file_buff)));
|
||||
}
|
||||
|
||||
file_buff = "this is a slave buff".getBytes(ClientGlobal.g_charset);
|
||||
file_ext_name = "txt";
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.append_file1(appender_file_id, file_buff);
|
||||
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println(client.get_file_info1(appender_file_id));
|
||||
} else {
|
||||
System.err.println("append file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.delete_file1(appender_file_id);
|
||||
System.out.println("delete_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println("Delete file success");
|
||||
} else {
|
||||
System.err.println("Delete file fail, error no: " + errno);
|
||||
}
|
||||
}
|
||||
|
||||
appender_file_id = client.upload_appender_file1(local_filename, null, meta_list);
|
||||
if (appender_file_id != null) {
|
||||
int ts;
|
||||
String token;
|
||||
String file_url;
|
||||
InetSocketAddress inetSockAddr;
|
||||
|
||||
inetSockAddr = trackerServer.getInetSocketAddress();
|
||||
file_url = "http://" + inetSockAddr.getAddress().getHostAddress();
|
||||
if (ClientGlobal.g_tracker_http_port != 80) {
|
||||
file_url += ":" + ClientGlobal.g_tracker_http_port;
|
||||
}
|
||||
file_url += "/" + appender_file_id;
|
||||
if (ClientGlobal.g_anti_steal_token) {
|
||||
ts = (int) (System.currentTimeMillis() / 1000);
|
||||
token = ProtoCommon.getToken(appender_file_id, ts, ClientGlobal.g_secret_key);
|
||||
file_url += "?token=" + token + "&ts=" + ts;
|
||||
}
|
||||
|
||||
System.err.println(client.get_file_info1(appender_file_id));
|
||||
System.err.println("file url: " + file_url);
|
||||
|
||||
errno = client.download_file1(appender_file_id, 0, 0, "c:\\" + appender_file_id.replaceAll("/", "_"));
|
||||
if (errno == 0) {
|
||||
System.err.println("Download file success");
|
||||
} else {
|
||||
System.err.println("Download file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
errno = client.download_file1(appender_file_id, 0, 0, new DownloadFileWriter("c:\\" + appender_file_id.replaceAll("/", "-")));
|
||||
if (errno == 0) {
|
||||
System.err.println("Download file success");
|
||||
} else {
|
||||
System.err.println("Download file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
file_ext_name = null;
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.append_file1(appender_file_id, local_filename);
|
||||
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println(client.get_file_info1(appender_file_id));
|
||||
} else {
|
||||
System.err.println("append file fail, error no: " + errno);
|
||||
}
|
||||
}
|
||||
|
||||
File f;
|
||||
f = new File(local_filename);
|
||||
int nPos = local_filename.lastIndexOf('.');
|
||||
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) {
|
||||
file_ext_name = local_filename.substring(nPos + 1);
|
||||
} else {
|
||||
file_ext_name = null;
|
||||
}
|
||||
|
||||
appender_file_id = client.upload_appender_file1(null, f.length(),
|
||||
new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
|
||||
if (appender_file_id != null) {
|
||||
System.out.println(client.get_file_info1(appender_file_id));
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.append_file1(appender_file_id, f.length(), new UploadLocalFileSender(local_filename));
|
||||
System.out.println("append_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println(client.get_file_info1(appender_file_id));
|
||||
} else {
|
||||
System.err.println("append file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.modify_file1(appender_file_id, 0, f.length(), new UploadLocalFileSender(local_filename));
|
||||
System.out.println("modify_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println(client.get_file_info1(appender_file_id));
|
||||
} else {
|
||||
System.err.println("modify file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.truncate_file1(appender_file_id, 0);
|
||||
System.out.println("truncate_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println(client.get_file_info1(appender_file_id));
|
||||
} else {
|
||||
System.err.println("truncate file fail, error no: " + errno);
|
||||
}
|
||||
} else {
|
||||
System.err.println("Upload file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
storageServer = tracker.getFetchStorage1(trackerServer, appender_file_id);
|
||||
if (storageServer == null) {
|
||||
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
|
||||
return;
|
||||
}
|
||||
/* for test only */
|
||||
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
|
||||
|
||||
storageServer.close();
|
||||
|
||||
/* for test only */
|
||||
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
|
||||
|
||||
trackerServer.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,304 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
* <p>
|
||||
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
|
||||
* General Public License (LGPL).
|
||||
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
|
||||
**/
|
||||
|
||||
package org.csource.fastdfs.test;
|
||||
|
||||
import org.csource.common.NameValuePair;
|
||||
import org.csource.fastdfs.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* client test
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.18
|
||||
*/
|
||||
public class TestClient {
|
||||
private TestClient() {
|
||||
}
|
||||
|
||||
/**
|
||||
* entry point
|
||||
*
|
||||
* @param args comand arguments
|
||||
* <ul><li>args[0]: config filename</li></ul>
|
||||
* <ul><li>args[1]: local filename to upload</li></ul>
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
if (args.length < 2) {
|
||||
System.out.println("Error: Must have 2 parameters, one is config filename, "
|
||||
+ "the other is the local filename to upload");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("java.version=" + System.getProperty("java.version"));
|
||||
|
||||
String conf_filename = args[0];
|
||||
String local_filename = args[1];
|
||||
|
||||
try {
|
||||
ClientGlobal.init(conf_filename);
|
||||
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
|
||||
System.out.println("charset=" + ClientGlobal.g_charset);
|
||||
|
||||
long startTime;
|
||||
String group_name;
|
||||
String remote_filename;
|
||||
ServerInfo[] servers;
|
||||
TrackerClient tracker = new TrackerClient();
|
||||
TrackerServer trackerServer = tracker.getConnection();
|
||||
|
||||
StorageServer storageServer = null;
|
||||
|
||||
/*
|
||||
storageServer = tracker.getStoreStorage(trackerServer);
|
||||
if (storageServer == null)
|
||||
{
|
||||
System.out.println("getStoreStorage fail, error code: " + tracker.getErrorCode());
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
StorageClient client = new StorageClient(trackerServer, storageServer);
|
||||
byte[] file_buff;
|
||||
NameValuePair[] meta_list;
|
||||
String[] results;
|
||||
String master_filename;
|
||||
String prefix_name;
|
||||
String file_ext_name;
|
||||
String generated_slave_filename;
|
||||
int errno;
|
||||
|
||||
meta_list = new NameValuePair[4];
|
||||
meta_list[0] = new NameValuePair("width", "800");
|
||||
meta_list[1] = new NameValuePair("heigth", "600");
|
||||
meta_list[2] = new NameValuePair("bgcolor", "#FFFFFF");
|
||||
meta_list[3] = new NameValuePair("author", "Mike");
|
||||
|
||||
file_buff = "this is a test".getBytes(ClientGlobal.g_charset);
|
||||
System.out.println("file length: " + file_buff.length);
|
||||
|
||||
group_name = null;
|
||||
StorageServer[] storageServers = tracker.getStoreStorages(trackerServer, group_name);
|
||||
if (storageServers == null) {
|
||||
System.err.println("get store storage servers fail, error code: " + tracker.getErrorCode());
|
||||
} else {
|
||||
System.err.println("store storage servers count: " + storageServers.length);
|
||||
for (int k = 0; k < storageServers.length; k++) {
|
||||
System.err.println((k + 1) + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort());
|
||||
}
|
||||
System.err.println("");
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
results = client.upload_file(file_buff, "txt", meta_list);
|
||||
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
|
||||
/*
|
||||
group_name = "";
|
||||
results = client.upload_file(group_name, file_buff, "txt", meta_list);
|
||||
*/
|
||||
if (results == null) {
|
||||
System.err.println("upload file fail, error code: " + client.getErrorCode());
|
||||
return;
|
||||
} else {
|
||||
group_name = results[0];
|
||||
remote_filename = results[1];
|
||||
System.err.println("group_name: " + group_name + ", remote_filename: " + remote_filename);
|
||||
System.err.println(client.get_file_info(group_name, remote_filename));
|
||||
|
||||
servers = tracker.getFetchStorages(trackerServer, group_name, remote_filename);
|
||||
if (servers == null) {
|
||||
System.err.println("get storage servers fail, error code: " + tracker.getErrorCode());
|
||||
} else {
|
||||
System.err.println("storage servers count: " + servers.length);
|
||||
for (int k = 0; k < servers.length; k++) {
|
||||
System.err.println((k + 1) + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort());
|
||||
}
|
||||
System.err.println("");
|
||||
}
|
||||
|
||||
meta_list = new NameValuePair[4];
|
||||
meta_list[0] = new NameValuePair("width", "1024");
|
||||
meta_list[1] = new NameValuePair("heigth", "768");
|
||||
meta_list[2] = new NameValuePair("bgcolor", "#000000");
|
||||
meta_list[3] = new NameValuePair("title", "Untitle");
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.set_metadata(group_name, remote_filename, meta_list, ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE);
|
||||
System.out.println("set_metadata time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println("set_metadata success");
|
||||
} else {
|
||||
System.err.println("set_metadata fail, error no: " + errno);
|
||||
}
|
||||
|
||||
meta_list = client.get_metadata(group_name, remote_filename);
|
||||
if (meta_list != null) {
|
||||
for (int i = 0; i < meta_list.length; i++) {
|
||||
System.out.println(meta_list[i].getName() + " " + meta_list[i].getValue());
|
||||
}
|
||||
}
|
||||
|
||||
//Thread.sleep(30000);
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
file_buff = client.download_file(group_name, remote_filename);
|
||||
System.out.println("download_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
|
||||
if (file_buff != null) {
|
||||
System.out.println("file length:" + file_buff.length);
|
||||
System.out.println((new String(file_buff)));
|
||||
}
|
||||
|
||||
file_buff = "this is a slave buff".getBytes(ClientGlobal.g_charset);
|
||||
master_filename = remote_filename;
|
||||
prefix_name = "-part1";
|
||||
file_ext_name = "txt";
|
||||
startTime = System.currentTimeMillis();
|
||||
results = client.upload_file(group_name, master_filename, prefix_name, file_buff, file_ext_name, meta_list);
|
||||
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (results != null) {
|
||||
System.err.println("slave file group_name: " + results[0] + ", remote_filename: " + results[1]);
|
||||
|
||||
generated_slave_filename = ProtoCommon.genSlaveFilename(master_filename, prefix_name, file_ext_name);
|
||||
if (!generated_slave_filename.equals(results[1])) {
|
||||
System.err.println("generated slave file: " + generated_slave_filename + "\n != returned slave file: " + results[1]);
|
||||
}
|
||||
|
||||
System.err.println(client.get_file_info(results[0], results[1]));
|
||||
}
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
errno = client.delete_file(group_name, remote_filename);
|
||||
System.out.println("delete_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (errno == 0) {
|
||||
System.err.println("Delete file success");
|
||||
} else {
|
||||
System.err.println("Delete file fail, error no: " + errno);
|
||||
}
|
||||
}
|
||||
|
||||
results = client.upload_file(local_filename, null, meta_list);
|
||||
if (results != null) {
|
||||
String file_id;
|
||||
int ts;
|
||||
String token;
|
||||
String file_url;
|
||||
InetSocketAddress inetSockAddr;
|
||||
|
||||
group_name = results[0];
|
||||
remote_filename = results[1];
|
||||
file_id = group_name + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remote_filename;
|
||||
|
||||
inetSockAddr = trackerServer.getInetSocketAddress();
|
||||
file_url = "http://" + inetSockAddr.getAddress().getHostAddress();
|
||||
if (ClientGlobal.g_tracker_http_port != 80) {
|
||||
file_url += ":" + ClientGlobal.g_tracker_http_port;
|
||||
}
|
||||
file_url += "/" + file_id;
|
||||
if (ClientGlobal.g_anti_steal_token) {
|
||||
ts = (int) (System.currentTimeMillis() / 1000);
|
||||
token = ProtoCommon.getToken(file_id, ts, ClientGlobal.g_secret_key);
|
||||
file_url += "?token=" + token + "&ts=" + ts;
|
||||
}
|
||||
|
||||
System.err.println("group_name: " + group_name + ", remote_filename: " + remote_filename);
|
||||
System.err.println(client.get_file_info(group_name, remote_filename));
|
||||
System.err.println("file url: " + file_url);
|
||||
|
||||
errno = client.download_file(group_name, remote_filename, 0, 0, "c:\\" + remote_filename.replaceAll("/", "_"));
|
||||
if (errno == 0) {
|
||||
System.err.println("Download file success");
|
||||
} else {
|
||||
System.err.println("Download file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
errno = client.download_file(group_name, remote_filename, 0, 0, new DownloadFileWriter("c:\\" + remote_filename.replaceAll("/", "-")));
|
||||
if (errno == 0) {
|
||||
System.err.println("Download file success");
|
||||
} else {
|
||||
System.err.println("Download file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
master_filename = remote_filename;
|
||||
prefix_name = "-part2";
|
||||
file_ext_name = null;
|
||||
startTime = System.currentTimeMillis();
|
||||
results = client.upload_file(group_name, master_filename, prefix_name, local_filename, null, meta_list);
|
||||
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (results != null) {
|
||||
System.err.println("slave file group_name: " + results[0] + ", remote_filename: " + results[1]);
|
||||
|
||||
generated_slave_filename = ProtoCommon.genSlaveFilename(master_filename, prefix_name, file_ext_name);
|
||||
if (!generated_slave_filename.equals(results[1])) {
|
||||
System.err.println("generated slave file: " + generated_slave_filename + "\n != returned slave file: " + results[1]);
|
||||
}
|
||||
|
||||
System.err.println(client.get_file_info(results[0], results[1]));
|
||||
}
|
||||
}
|
||||
|
||||
File f;
|
||||
f = new File(local_filename);
|
||||
int nPos = local_filename.lastIndexOf('.');
|
||||
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) {
|
||||
file_ext_name = local_filename.substring(nPos + 1);
|
||||
} else {
|
||||
file_ext_name = null;
|
||||
}
|
||||
|
||||
results = client.upload_file(null, f.length(),
|
||||
new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
|
||||
if (results != null) {
|
||||
group_name = results[0];
|
||||
remote_filename = results[1];
|
||||
|
||||
System.out.println("group name: " + group_name + ", remote filename: " + remote_filename);
|
||||
System.out.println(client.get_file_info(group_name, remote_filename));
|
||||
|
||||
master_filename = remote_filename;
|
||||
prefix_name = "-part3";
|
||||
startTime = System.currentTimeMillis();
|
||||
results = client.upload_file(group_name, master_filename, prefix_name, f.length(), new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
|
||||
System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
if (results != null) {
|
||||
System.err.println("slave file group_name: " + results[0] + ", remote_filename: " + results[1]);
|
||||
|
||||
generated_slave_filename = ProtoCommon.genSlaveFilename(master_filename, prefix_name, file_ext_name);
|
||||
if (!generated_slave_filename.equals(results[1])) {
|
||||
System.err.println("generated slave file: " + generated_slave_filename + "\n != returned slave file: " + results[1]);
|
||||
}
|
||||
|
||||
System.err.println(client.get_file_info(results[0], results[1]));
|
||||
}
|
||||
} else {
|
||||
System.err.println("Upload file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
storageServer = tracker.getFetchStorage(trackerServer, group_name, remote_filename);
|
||||
if (storageServer == null) {
|
||||
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
|
||||
return;
|
||||
}
|
||||
/* for test only */
|
||||
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
|
||||
|
||||
storageServer.close();
|
||||
|
||||
/* for test only */
|
||||
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
|
||||
|
||||
trackerServer.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,266 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
* <p>
|
||||
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
|
||||
* General Public License (LGPL).
|
||||
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
|
||||
**/
|
||||
|
||||
package org.csource.fastdfs.test;
|
||||
|
||||
import org.csource.common.NameValuePair;
|
||||
import org.csource.fastdfs.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* client test
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.16
|
||||
*/
|
||||
public class TestClient1 {
|
||||
private TestClient1() {
|
||||
}
|
||||
|
||||
/**
|
||||
* entry point
|
||||
*
|
||||
* @param args comand arguments
|
||||
* <ul><li>args[0]: config filename</li></ul>
|
||||
* <ul><li>args[1]: local filename to upload</li></ul>
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
if (args.length < 2) {
|
||||
System.out.println("Error: Must have 2 parameters, one is config filename, "
|
||||
+ "the other is the local filename to upload");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("java.version=" + System.getProperty("java.version"));
|
||||
|
||||
String conf_filename = args[0];
|
||||
String local_filename = args[1];
|
||||
String group_name;
|
||||
|
||||
try {
|
||||
ClientGlobal.init(conf_filename);
|
||||
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
|
||||
System.out.println("charset=" + ClientGlobal.g_charset);
|
||||
|
||||
String file_id;
|
||||
|
||||
TrackerClient tracker = new TrackerClient();
|
||||
TrackerServer trackerServer = tracker.getConnection();
|
||||
|
||||
StorageServer storageServer = null;
|
||||
/*
|
||||
storageServer = tracker.getStoreStorage(trackerServer);
|
||||
if (storageServer == null)
|
||||
{
|
||||
System.out.println("getStoreStorage fail, error code: " + tracker.getErrorCode());
|
||||
return;
|
||||
}
|
||||
*/
|
||||
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
|
||||
byte[] file_buff;
|
||||
NameValuePair[] meta_list;
|
||||
String master_file_id;
|
||||
String prefix_name;
|
||||
String file_ext_name;
|
||||
String slave_file_id;
|
||||
String generated_slave_file_id;
|
||||
int errno;
|
||||
|
||||
group_name = "group1";
|
||||
StorageServer[] storageServers = tracker.getStoreStorages(trackerServer, group_name);
|
||||
if (storageServers == null) {
|
||||
System.err.println("get store storage servers fail, error code: " + tracker.getErrorCode());
|
||||
} else {
|
||||
System.err.println("store storage servers count: " + storageServers.length);
|
||||
for (int k = 0; k < storageServers.length; k++) {
|
||||
System.err.println((k + 1) + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort());
|
||||
}
|
||||
System.err.println("");
|
||||
}
|
||||
|
||||
meta_list = new NameValuePair[4];
|
||||
meta_list[0] = new NameValuePair("width", "800");
|
||||
meta_list[1] = new NameValuePair("heigth", "600");
|
||||
meta_list[2] = new NameValuePair("bgcolor", "#FFFFFF");
|
||||
meta_list[3] = new NameValuePair("author", "Mike");
|
||||
|
||||
file_buff = "this is a test".getBytes(ClientGlobal.g_charset);
|
||||
System.out.println("file length: " + file_buff.length);
|
||||
|
||||
file_id = client.upload_file1(file_buff, "txt", meta_list);
|
||||
/*
|
||||
group_name = "group1";
|
||||
file_id = client.upload_file1(group_name, file_buff, "txt", meta_list);
|
||||
*/
|
||||
if (file_id == null) {
|
||||
System.err.println("upload file fail, error code: " + client.getErrorCode());
|
||||
return;
|
||||
} else {
|
||||
System.err.println("file_id: " + file_id);
|
||||
System.err.println(client.get_file_info1(file_id));
|
||||
|
||||
ServerInfo[] servers = tracker.getFetchStorages1(trackerServer, file_id);
|
||||
if (servers == null) {
|
||||
System.err.println("get storage servers fail, error code: " + tracker.getErrorCode());
|
||||
} else {
|
||||
System.err.println("storage servers count: " + servers.length);
|
||||
for (int k = 0; k < servers.length; k++) {
|
||||
System.err.println((k + 1) + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort());
|
||||
}
|
||||
System.err.println("");
|
||||
}
|
||||
|
||||
meta_list = new NameValuePair[4];
|
||||
meta_list[0] = new NameValuePair("width", "1024");
|
||||
meta_list[1] = new NameValuePair("heigth", "768");
|
||||
meta_list[2] = new NameValuePair("bgcolor", "#000000");
|
||||
meta_list[3] = new NameValuePair("title", "Untitle");
|
||||
|
||||
if ((errno = client.set_metadata1(file_id, meta_list, ProtoCommon.STORAGE_SET_METADATA_FLAG_MERGE)) == 0) {
|
||||
System.err.println("set_metadata success");
|
||||
} else {
|
||||
System.err.println("set_metadata fail, error no: " + errno);
|
||||
}
|
||||
|
||||
meta_list = client.get_metadata1(file_id);
|
||||
if (meta_list != null) {
|
||||
for (int i = 0; i < meta_list.length; i++) {
|
||||
System.out.println(meta_list[i].getName() + " " + meta_list[i].getValue());
|
||||
}
|
||||
}
|
||||
|
||||
//Thread.sleep(30000);
|
||||
|
||||
file_buff = client.download_file1(file_id);
|
||||
if (file_buff != null) {
|
||||
System.out.println("file length:" + file_buff.length);
|
||||
System.out.println((new String(file_buff)));
|
||||
}
|
||||
|
||||
master_file_id = file_id;
|
||||
prefix_name = "-part1";
|
||||
file_ext_name = "txt";
|
||||
file_buff = "this is a slave buff.".getBytes(ClientGlobal.g_charset);
|
||||
slave_file_id = client.upload_file1(master_file_id, prefix_name, file_buff, file_ext_name, meta_list);
|
||||
if (slave_file_id != null) {
|
||||
System.err.println("slave file_id: " + slave_file_id);
|
||||
System.err.println(client.get_file_info1(slave_file_id));
|
||||
|
||||
generated_slave_file_id = ProtoCommon.genSlaveFilename(master_file_id, prefix_name, file_ext_name);
|
||||
if (!generated_slave_file_id.equals(slave_file_id)) {
|
||||
System.err.println("generated slave file: " + generated_slave_file_id + "\n != returned slave file: " + slave_file_id);
|
||||
}
|
||||
}
|
||||
|
||||
//Thread.sleep(10000);
|
||||
if ((errno = client.delete_file1(file_id)) == 0) {
|
||||
System.err.println("Delete file success");
|
||||
} else {
|
||||
System.err.println("Delete file fail, error no: " + errno);
|
||||
}
|
||||
}
|
||||
|
||||
if ((file_id = client.upload_file1(local_filename, null, meta_list)) != null) {
|
||||
int ts;
|
||||
String token;
|
||||
String file_url;
|
||||
InetSocketAddress inetSockAddr;
|
||||
|
||||
System.err.println("file_id: " + file_id);
|
||||
System.err.println(client.get_file_info1(file_id));
|
||||
|
||||
inetSockAddr = trackerServer.getInetSocketAddress();
|
||||
file_url = "http://" + inetSockAddr.getAddress().getHostAddress();
|
||||
if (ClientGlobal.g_tracker_http_port != 80) {
|
||||
file_url += ":" + ClientGlobal.g_tracker_http_port;
|
||||
}
|
||||
file_url += "/" + file_id;
|
||||
if (ClientGlobal.g_anti_steal_token) {
|
||||
ts = (int) (System.currentTimeMillis() / 1000);
|
||||
token = ProtoCommon.getToken(file_id, ts, ClientGlobal.g_secret_key);
|
||||
file_url += "?token=" + token + "&ts=" + ts;
|
||||
}
|
||||
System.err.println("file url: " + file_url);
|
||||
|
||||
errno = client.download_file1(file_id, 0, 100, "c:\\" + file_id.replaceAll("/", "_"));
|
||||
if (errno == 0) {
|
||||
System.err.println("Download file success");
|
||||
} else {
|
||||
System.err.println("Download file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
errno = client.download_file1(file_id, new DownloadFileWriter("c:\\" + file_id.replaceAll("/", "-")));
|
||||
if (errno == 0) {
|
||||
System.err.println("Download file success");
|
||||
} else {
|
||||
System.err.println("Download file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
master_file_id = file_id;
|
||||
prefix_name = "-part2";
|
||||
file_ext_name = null;
|
||||
slave_file_id = client.upload_file1(master_file_id, prefix_name, local_filename, file_ext_name, meta_list);
|
||||
if (slave_file_id != null) {
|
||||
System.err.println("slave file_id: " + slave_file_id);
|
||||
System.err.println(client.get_file_info1(slave_file_id));
|
||||
|
||||
generated_slave_file_id = ProtoCommon.genSlaveFilename(master_file_id, prefix_name, file_ext_name);
|
||||
if (!generated_slave_file_id.equals(slave_file_id)) {
|
||||
System.err.println("generated slave file: " + generated_slave_file_id + "\n != returned slave file: " + slave_file_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File f;
|
||||
f = new File(local_filename);
|
||||
int nPos = local_filename.lastIndexOf('.');
|
||||
if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) {
|
||||
file_ext_name = local_filename.substring(nPos + 1);
|
||||
} else {
|
||||
file_ext_name = null;
|
||||
}
|
||||
|
||||
file_id = client.upload_file1(null, f.length(), new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
|
||||
if (file_id != null) {
|
||||
System.out.println("file id: " + file_id);
|
||||
System.out.println(client.get_file_info1(file_id));
|
||||
master_file_id = file_id;
|
||||
prefix_name = "-part3";
|
||||
slave_file_id = client.upload_file1(master_file_id, prefix_name, f.length(), new UploadLocalFileSender(local_filename), file_ext_name, meta_list);
|
||||
if (slave_file_id != null) {
|
||||
System.err.println("slave file_id: " + slave_file_id);
|
||||
generated_slave_file_id = ProtoCommon.genSlaveFilename(master_file_id, prefix_name, file_ext_name);
|
||||
if (!generated_slave_file_id.equals(slave_file_id)) {
|
||||
System.err.println("generated slave file: " + generated_slave_file_id + "\n != returned slave file: " + slave_file_id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.err.println("Upload file fail, error no: " + errno);
|
||||
}
|
||||
|
||||
storageServer = tracker.getFetchStorage1(trackerServer, file_id);
|
||||
if (storageServer == null) {
|
||||
System.out.println("getFetchStorage fail, errno code: " + tracker.getErrorCode());
|
||||
return;
|
||||
}
|
||||
|
||||
/* for test only */
|
||||
System.out.println("active test to storage server: " + ProtoCommon.activeTest(storageServer.getSocket()));
|
||||
storageServer.close();
|
||||
|
||||
/* for test only */
|
||||
System.out.println("active test to tracker server: " + ProtoCommon.activeTest(trackerServer.getSocket()));
|
||||
|
||||
trackerServer.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,263 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
* <p>
|
||||
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
|
||||
* General Public License (LGPL).
|
||||
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
|
||||
**/
|
||||
|
||||
package org.csource.fastdfs.test;
|
||||
|
||||
import org.csource.fastdfs.*;
|
||||
|
||||
/**
|
||||
* load test class
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.11
|
||||
*/
|
||||
public class TestLoad {
|
||||
public static java.util.concurrent.ConcurrentLinkedQueue file_ids;
|
||||
public static int total_download_count = 0;
|
||||
public static int success_download_count = 0;
|
||||
public static int fail_download_count = 0;
|
||||
public static int total_upload_count = 0;
|
||||
public static int success_upload_count = 0;
|
||||
public static int upload_thread_count = 0;
|
||||
|
||||
private TestLoad() {
|
||||
}
|
||||
|
||||
/**
|
||||
* entry point
|
||||
*
|
||||
* @param args comand arguments
|
||||
* <ul><li>args[0]: config filename</li></ul>
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
if (args.length < 1) {
|
||||
System.out.println("Error: Must have 1 parameter: config filename");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("java.version=" + System.getProperty("java.version"));
|
||||
|
||||
try {
|
||||
ClientGlobal.init(args[0]);
|
||||
System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms");
|
||||
System.out.println("charset=" + ClientGlobal.g_charset);
|
||||
|
||||
file_ids = new java.util.concurrent.ConcurrentLinkedQueue();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
(new UploadThread(i)).start();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
(new DownloadThread(i)).start();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* discard file content callback class when download file
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.0
|
||||
*/
|
||||
public static class DownloadFileDiscard implements DownloadCallback {
|
||||
public DownloadFileDiscard() {
|
||||
}
|
||||
|
||||
public int recv(long file_size, byte[] data, int bytes) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* file uploader
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.0
|
||||
*/
|
||||
public static class Uploader {
|
||||
public TrackerClient tracker;
|
||||
public TrackerServer trackerServer;
|
||||
|
||||
public Uploader() throws Exception {
|
||||
this.tracker = new TrackerClient();
|
||||
this.trackerServer = tracker.getConnection();
|
||||
}
|
||||
|
||||
public int uploadFile() throws Exception {
|
||||
StorageServer storageServer = null;
|
||||
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
|
||||
byte[] file_buff;
|
||||
String file_id;
|
||||
|
||||
file_buff = new byte[2 * 1024];
|
||||
java.util.Arrays.fill(file_buff, (byte) 65);
|
||||
|
||||
try {
|
||||
file_id = client.upload_file1(file_buff, "txt", null);
|
||||
if (file_id == null) {
|
||||
System.out.println("upload file fail, error code: " + client.getErrorCode());
|
||||
return -1;
|
||||
}
|
||||
|
||||
TestLoad.file_ids.offer(file_id);
|
||||
return 0;
|
||||
} catch (Exception ex) {
|
||||
System.out.println("upload file fail, error mesg: " + ex.getMessage());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* file downloader
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.0
|
||||
*/
|
||||
public static class Downloader {
|
||||
public TrackerClient tracker;
|
||||
public TrackerServer trackerServer;
|
||||
public DownloadFileDiscard callback;
|
||||
|
||||
public Downloader() throws Exception {
|
||||
this.tracker = new TrackerClient();
|
||||
this.trackerServer = tracker.getConnection();
|
||||
this.callback = new DownloadFileDiscard();
|
||||
}
|
||||
|
||||
public int downloadFile(String file_id) throws Exception {
|
||||
int errno;
|
||||
StorageServer storageServer = null;
|
||||
StorageClient1 client = new StorageClient1(trackerServer, storageServer);
|
||||
|
||||
try {
|
||||
errno = client.download_file1(file_id, this.callback);
|
||||
if (errno != 0) {
|
||||
System.out.println("Download file fail, file_id: " + file_id + ", error no: " + errno);
|
||||
}
|
||||
return errno;
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Download file fail, error mesg: " + ex.getMessage());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* upload file thread
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.0
|
||||
*/
|
||||
public static class UploadThread extends Thread {
|
||||
private int thread_index;
|
||||
|
||||
public UploadThread(int index) {
|
||||
this.thread_index = index;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
TestLoad.upload_thread_count++;
|
||||
Uploader uploader = new Uploader();
|
||||
|
||||
System.out.println("upload thread " + this.thread_index + " start");
|
||||
|
||||
for (int i = 0; i < 50000; i++) {
|
||||
TestLoad.total_upload_count++;
|
||||
if (uploader.uploadFile() == 0) {
|
||||
TestLoad.success_upload_count++;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
TestLoad.upload_thread_count--;
|
||||
}
|
||||
|
||||
System.out.println("upload thread " + this.thread_index
|
||||
+ " exit, total_upload_count: " + TestLoad.total_upload_count
|
||||
+ ", success_upload_count: " + TestLoad.success_upload_count
|
||||
+ ", total_download_count: " + TestLoad.total_download_count
|
||||
+ ", success_download_count: " + TestLoad.success_download_count);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* download file thread
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.0
|
||||
*/
|
||||
public static class DownloadThread extends Thread {
|
||||
private static Integer counter_lock = new Integer(0);
|
||||
private int thread_index;
|
||||
|
||||
public DownloadThread(int index) {
|
||||
this.thread_index = index;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
String file_id;
|
||||
Downloader downloader = new Downloader();
|
||||
|
||||
System.out.println("download thread " + this.thread_index + " start");
|
||||
|
||||
file_id = "";
|
||||
while (TestLoad.upload_thread_count != 0 || file_id != null) {
|
||||
file_id = (String) TestLoad.file_ids.poll();
|
||||
if (file_id == null) {
|
||||
Thread.sleep(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
synchronized (this.counter_lock) {
|
||||
TestLoad.total_download_count++;
|
||||
}
|
||||
if (downloader.downloadFile(file_id) == 0) {
|
||||
synchronized (this.counter_lock) {
|
||||
TestLoad.success_download_count++;
|
||||
}
|
||||
} else {
|
||||
TestLoad.fail_download_count++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3 && TestLoad.total_download_count < TestLoad.total_upload_count; i++) {
|
||||
file_id = (String) TestLoad.file_ids.poll();
|
||||
if (file_id == null) {
|
||||
Thread.sleep(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
synchronized (this.counter_lock) {
|
||||
TestLoad.total_download_count++;
|
||||
}
|
||||
if (downloader.downloadFile(file_id) == 0) {
|
||||
synchronized (this.counter_lock) {
|
||||
TestLoad.success_download_count++;
|
||||
}
|
||||
} else {
|
||||
TestLoad.fail_download_count++;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("download thread " + this.thread_index
|
||||
+ " exit, total_download_count: " + TestLoad.total_download_count
|
||||
+ ", success_download_count: " + TestLoad.success_download_count
|
||||
+ ", fail_download_count: " + TestLoad.fail_download_count);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2008 Happy Fish / YuQing
|
||||
* <p>
|
||||
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
|
||||
* General Public License (LGPL).
|
||||
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
|
||||
*/
|
||||
|
||||
package org.csource.fastdfs.test;
|
||||
|
||||
import org.csource.fastdfs.UploadCallback;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* upload file callback class, local file sender
|
||||
*
|
||||
* @author Happy Fish / YuQing
|
||||
* @version Version 1.0
|
||||
*/
|
||||
public class UploadLocalFileSender implements UploadCallback {
|
||||
private String local_filename;
|
||||
|
||||
public UploadLocalFileSender(String szLocalFilename) {
|
||||
this.local_filename = szLocalFilename;
|
||||
}
|
||||
|
||||
/**
|
||||
* send file content callback function, be called only once when the file uploaded
|
||||
*
|
||||
* @param out output stream for writing file content
|
||||
* @return 0 success, return none zero(errno) if fail
|
||||
*/
|
||||
public int send(OutputStream out) throws IOException {
|
||||
FileInputStream fis;
|
||||
int readBytes;
|
||||
byte[] buff = new byte[256 * 1024];
|
||||
|
||||
fis = new FileInputStream(this.local_filename);
|
||||
try {
|
||||
while ((readBytes = fis.read(buff)) >= 0) {
|
||||
if (readBytes == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
out.write(buff, 0, readBytes);
|
||||
}
|
||||
} finally {
|
||||
fis.close();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user