Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions src/main/java/com/turn/ttorrent/common/Torrent.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public TorrentFile(File file, long size) {
* BitTorrent specification) and create a Torrent object from it.
*
* @param torrent The meta-info byte data.
* @param parent The parent directory or location of the torrent files.
* @param seeder Whether we'll be seeding for this torrent or not.
* @throws IOException When the info dictionary can't be read or
* encoded and hashed back to create the torrent's SHA-1 hash.
Expand Down Expand Up @@ -401,22 +402,14 @@ public boolean isSeeder() {
return this.seeder;
}

/**
/**
* Save this torrent meta-info structure into a .torrent file.
*
* @param file The file to write to.
* @param output The stream to write to.
* @throws IOException If an I/O error occurs while writing the file.
*/
public void save(File file) throws IOException {
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(file);
fOut.write(this.getEncoded());
} finally {
if (fOut != null){
fOut.close();
}
}
public void save(OutputStream output) throws IOException {
output.write(this.getEncoded());
}

public static byte[] hash(byte[] data) throws NoSuchAlgorithmException {
Expand Down Expand Up @@ -599,7 +592,7 @@ public static Torrent create(File source, List<List<URI>> announceList,
* considering we'll be a full initial seeder for it.
* </p>
*
* @param source The parent directory or location of the torrent files,
* @param parent The parent directory or location of the torrent files,
* also used as the torrent's name.
* @param files The files to add into this torrent.
* @param announceList The announce URIs organized as tiers that will
Expand Down Expand Up @@ -961,8 +954,8 @@ public static void main(String[] args) {
torrent = Torrent.create(source, announceURI, creator);
}

fos.write(torrent.getEncoded());
} else {
torrent.save(fos);
} else {
Torrent.load(new File(filenameValue), true);
}
} catch (Exception e) {
Expand Down
27 changes: 5 additions & 22 deletions src/main/java/com/turn/ttorrent/tracker/Tracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -51,7 +48,7 @@
* <p>
* The tracker usually listens on port 6969 (the standard BitTorrent tracker
* port). Torrents must be registered directly to this tracker with the
* {@link #announce(Torrent torrent)}</code> method.
* {@link #announce(TrackedTorrent torrent)}</code> method.
* </p>
*
* @author mpetazzoni
Expand Down Expand Up @@ -183,15 +180,7 @@ public void stop() {
}
}

public ConcurrentMap<String, TrackedTorrent> getTorrentsMap() {
return torrents;
}

public Collection<TrackedTorrent> getTrackedTorrents(){
return torrents.values();
}

/**
/**
* Announce a new torrent on this tracker.
*
* <p>
Expand All @@ -206,7 +195,7 @@ public Collection<TrackedTorrent> getTrackedTorrents(){
* different from the supplied Torrent object if the tracker already
* contained a torrent with the same hash.
*/
public synchronized TrackedTorrent announce(Torrent torrent) throws IOException, NoSuchAlgorithmException {
public synchronized TrackedTorrent announce(TrackedTorrent torrent) {
TrackedTorrent existing = this.torrents.get(torrent.getHexInfoHash());

if (existing != null) {
Expand All @@ -215,16 +204,10 @@ public synchronized TrackedTorrent announce(Torrent torrent) throws IOException,
return existing;
}

final TrackedTorrent result;
if (torrent instanceof TrackedTorrent) {
result = (TrackedTorrent) torrent;
} else {
result = new TrackedTorrent(torrent);
}
this.torrents.put(torrent.getHexInfoHash(), result);
this.torrents.put(torrent.getHexInfoHash(), torrent);
logger.info("Registered new torrent for '{}' with hash {}.",
torrent.getName(), torrent.getHexInfoHash());
return result;
return torrent;
}

/**
Expand Down
56 changes: 0 additions & 56 deletions src/test/java/com/turn/ttorrent/FileUtil.java

This file was deleted.

136 changes: 0 additions & 136 deletions src/test/java/com/turn/ttorrent/TempFiles.java

This file was deleted.

33 changes: 0 additions & 33 deletions src/test/java/com/turn/ttorrent/WaitFor.java

This file was deleted.

Loading