Search in sources :

Example 6 with TaskEntity

use of com.acgist.snail.pojo.entity.TaskEntity in project snail by acgist.

the class PropertyDescriptorTest method testSetter.

@Test
void testSetter() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    final String id = "1234";
    final TaskEntity task = new TaskEntity();
    assertNull(task.getId());
    PropertyDescriptor.newInstance(task).set("id", id);
    assertEquals(id, task.getId());
}
Also used : TaskEntity(com.acgist.snail.pojo.entity.TaskEntity) Test(org.junit.jupiter.api.Test)

Example 7 with TaskEntity

use of com.acgist.snail.pojo.entity.TaskEntity in project snail by acgist.

the class HlsContextTest method testHlsContext.

@Test
void testHlsContext() throws DownloadException {
    final String id = UUID.randomUUID().toString();
    final TaskEntity task = new TaskEntity();
    task.setId(id);
    task.setName("acgist");
    final ITaskSession session = TaskSession.newInstance(task);
    assertDoesNotThrow(() -> {
        HlsContext.getInstance().m3u8(id, new M3u8(Type.FILE, null, List.of()));
        HlsContext.getInstance().hlsSession(session);
        HlsContext.getInstance().remove(session);
    });
}
Also used : TaskEntity(com.acgist.snail.pojo.entity.TaskEntity) ITaskSession(com.acgist.snail.pojo.ITaskSession) M3u8(com.acgist.snail.pojo.bean.M3u8) Test(org.junit.jupiter.api.Test)

Example 8 with TaskEntity

use of com.acgist.snail.pojo.entity.TaskEntity in project snail by acgist.

the class LoggerTest method testLevel.

@Test
void testLevel() {
    String arga = null;
    String argb = "";
    final TaskEntity taskEntity = new TaskEntity();
    LOGGER.debug("debug:{}-{}-{}-{}", arga, argb, taskEntity);
    LOGGER.info("info:{}-{}-{}-{}", arga, argb, taskEntity);
    LOGGER.warn("warn:{}-{}-{}-{}", arga, argb, taskEntity);
    LOGGER.error("error:{}-{}-{}-{}", arga, argb, taskEntity);
    try {
        throw new NetException("错误测试");
    } catch (Exception e) {
        LOGGER.debug("debug", e);
        LOGGER.info("info", e);
        LOGGER.warn("warn", e);
        LOGGER.error("error", e);
    }
    assertNotNull(LOGGER);
}
Also used : TaskEntity(com.acgist.snail.pojo.entity.TaskEntity) NetException(com.acgist.snail.context.exception.NetException) NetException(com.acgist.snail.context.exception.NetException) Test(org.junit.jupiter.api.Test)

Example 9 with TaskEntity

use of com.acgist.snail.pojo.entity.TaskEntity in project snail by acgist.

the class TorrentStreamGroupTest method testPick.

@Test
void testPick() throws DownloadException {
    LoggerConfig.off();
    final var path = "E:/snail/07E1B909D8D193D80E440A8593FB57A658223A0E.torrent";
    final var session = TorrentContext.getInstance().newTorrentSession(path);
    final var entity = new TaskEntity();
    entity.setFile("E:/snail/tmp/pick/");
    entity.setType(Type.TORRENT);
    entity.setName("acgist");
    entity.setStatus(Status.AWAIT);
    final List<String> list = new ArrayList<>();
    session.torrent().getInfo().files().stream().filter(TorrentFile::notPaddingFile).forEach(file -> {
        file.selected(true);
        list.add(file.path());
    });
    entity.setDescription(DescriptionWrapper.newEncoder(list).serialize());
    session.upload(TaskSession.newInstance(entity));
    final var group = session.torrentStreamGroup();
    final BitSet peerPieces = new BitSet();
    peerPieces.set(0, session.torrent().getInfo().pieceSize(), true);
    final BitSet suggestPieces = new BitSet();
    this.cost();
    TorrentPiece index;
    final Set<Integer> indexSet = new HashSet<Integer>();
    while ((index = group.pick(peerPieces, suggestPieces)) != null) {
        this.log(index);
        group.done(index.getIndex());
        indexSet.add(index.getIndex());
    }
    assertEquals(session.torrent().getInfo().pieceSize(), indexSet.size());
    this.costed();
}
Also used : TaskEntity(com.acgist.snail.pojo.entity.TaskEntity) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) TorrentPiece(com.acgist.snail.pojo.bean.TorrentPiece) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 10 with TaskEntity

use of com.acgist.snail.pojo.entity.TaskEntity in project snail by acgist.

the class PeerServerTest method testServer.

@Test
void testServer() throws DownloadException {
    final var path = "E:/snail/902FFAA29EE632C8DC966ED9AB573409BA9A518E.torrent";
    final var torrentSession = TorrentContext.getInstance().newTorrentSession(path);
    DownloadConfig.setBuffer(40 * 1024);
    final List<String> list = new ArrayList<>();
    final AtomicLong size = new AtomicLong();
    torrentSession.torrent().getInfo().files().stream().filter(TorrentFile::notPaddingFile).forEach(file -> {
        if (file.path().contains("Scans/Vol.1")) {
            list.add(file.path());
        }
        size.addAndGet(file.getLength());
    });
    final var entity = new TaskEntity();
    entity.setFile("E:\\snail\\server");
    entity.setType(Type.TORRENT);
    entity.setSize(size.get());
    entity.setDescription(DescriptionWrapper.newEncoder(list).serialize());
    torrentSession.upload(TaskSession.newInstance(entity));
    torrentSession.verify();
    PeerServer.getInstance();
    TorrentServer.getInstance();
    ThreadUtils.sleep(100000);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TaskEntity(com.acgist.snail.pojo.entity.TaskEntity) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

TaskEntity (com.acgist.snail.pojo.entity.TaskEntity)15 Test (org.junit.jupiter.api.Test)14 ArrayList (java.util.ArrayList)3 BitSet (java.util.BitSet)2 Date (java.util.Date)2 Order (org.junit.jupiter.api.Order)2 NetException (com.acgist.snail.context.exception.NetException)1 ITaskSession (com.acgist.snail.pojo.ITaskSession)1 M3u8 (com.acgist.snail.pojo.bean.M3u8)1 TorrentFile (com.acgist.snail.pojo.bean.TorrentFile)1 TorrentPiece (com.acgist.snail.pojo.bean.TorrentPiece)1 StatisticsSession (com.acgist.snail.pojo.session.StatisticsSession)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1