diff --git a/src/main/java/org/csource/fastdfs/TrackerClient.java b/src/main/java/org/csource/fastdfs/TrackerClient.java index 529e945..8b8bd56 100644 --- a/src/main/java/org/csource/fastdfs/TrackerClient.java +++ b/src/main/java/org/csource/fastdfs/TrackerClient.java @@ -100,36 +100,37 @@ public class TrackerClient { return connection; } //do fail over - if (length > 1) { - int currentIndex = trackerServer.getIndex(); - int failOverCount = 0; - while (failOverCount < length - 1) { - failOverCount++; - currentIndex++; - if (currentIndex >= length) { - currentIndex = 0; - } - try { - trackerServer = this.tracker_group.getTrackerServer(currentIndex); - if (trackerServer == null) { - throw new MyException("tracker server is empty!"); - } - return trackerServer.getConnection(); - } catch (IOException e) { - System.err.println("fail over trackerServer get connection error, failOverCount:" + failOverCount + "," + e.getMessage()); - if (failOverCount == length - 1) { - throw e; - } - - } catch (MyException e) { - System.err.println("fail over trackerServer get connection error, failOverCount:" + failOverCount + ", " + e.getMessage()); - if (failOverCount == length - 1) { - throw e; - } - } - - + int currentIndex = 0; + if (trackerServer != null) { + currentIndex = trackerServer.getIndex(); + } + int failOverCount = 0; + while (failOverCount < length - 1) { + failOverCount++; + currentIndex++; + if (currentIndex >= length) { + currentIndex = 0; } + try { + trackerServer = this.tracker_group.getTrackerServer(currentIndex); + if (trackerServer == null) { + throw new MyException("tracker server is empty!"); + } + return trackerServer.getConnection(); + } catch (IOException e) { + System.err.println("fail over trackerServer get connection error, failOverCount:" + failOverCount + "," + e.getMessage()); + if (failOverCount == length - 1) { + throw e; + } + + } catch (MyException e) { + System.err.println("fail over trackerServer get connection error, failOverCount:" + failOverCount + ", " + e.getMessage()); + if (failOverCount == length - 1) { + throw e; + } + } + + } return null; } diff --git a/src/test/java/org/csource/fastdfs/FdfsTest.java b/src/test/java/org/csource/fastdfs/FdfsTest.java index 1cb2702..74f3e6e 100644 --- a/src/test/java/org/csource/fastdfs/FdfsTest.java +++ b/src/test/java/org/csource/fastdfs/FdfsTest.java @@ -33,7 +33,7 @@ public class FdfsTest { TrackerClient tracker = new TrackerClient(); trackerServer = tracker.getTrackerServer(); StorageServer storageServer = null; - storageClient = new StorageClient(null, storageServer); + storageClient = new StorageClient(trackerServer, storageServer); } @After @@ -87,9 +87,9 @@ public class FdfsTest { @Test public void download() throws Exception { - String[] uploadresult = {"group1", "M00/00/00/wKgBZV0phl2ASV1nAACk1tFxwrM3814331"}; + String[] uploadresult = {"group1", "M00/00/00/J2fL12PVypeAWiGcAAM_gDeWVyw5817085"}; byte[] result = storageClient.download_file(uploadresult[0], uploadresult[1]); - String local_filename = "build.PNG"; + String local_filename = "commitment.d2f57e10.jpg"; writeByteToFile(result, local_filename); File file = new File(local_filename); Assert.assertTrue(file.isFile());