package cn.com.qmth.stmms.biz.test.util;

import java.util.ArrayList;
import java.util.List;

import cn.com.qmth.stmms.biz.exam.model.Marker;
import cn.com.qmth.stmms.biz.utils.CurrentTaskUtil2;

public class TaskTestThread implements Runnable {

    private Marker marker;

    public TaskTestThread(Marker marker) {
        this.marker = marker;
    }

    @Override
    public void run() {
        List<Integer> current = new ArrayList<Integer>();
        for (int i = 1; i <= 100; i++) {
            if (CurrentTaskUtil2.add(marker, i)) {
                current.add(i);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {

                }
                System.out.println("1\t" + marker.getId() + "\t" + i);
            }

            if (current.size() == 5) {
                int index = (int) Math.random() * 4;
                int libraryId = current.get(index);
                CurrentTaskUtil2.remove(marker, libraryId);
                current.remove(index);
                System.out.println("0\t" + marker.getId() + "\t" + libraryId);
                if (CurrentTaskUtil2.count(marker) != 4) {
                    System.out.println("remove error");
                }
            }
        }

        // if (current.size() > 0) {
        // CurrentTaskUtil2.clear(marker);
        // current.clear();
        // }
    }
}
