package com.qiniu.android;

import com.qiniu.android.transaction.TransactionManager;
import com.qiniu.android.utils.LogUtil;

import java.util.Date;

/**
 * Created by yangsen on 2020/6/9
 */
public class TransactionManagerTest extends BaseTest {

    public void testTransaction(){

        TransactionManager.Transaction normal = new TransactionManager.Transaction("1", 0, new Runnable() {
            @Override
            public void run() {
                LogUtil.d("1");
            }
        });
        assertNotNull(normal);


        TransactionManager.Transaction time = new TransactionManager.Transaction("1", 0, 1, new Runnable() {
            @Override
            public void run() {
                LogUtil.d("2");
            }
        });
        assertNotNull(time);
    }

    public void testTransactionManagerAddAndRemove(){

        String normalName = "testNormalTransaction";
        TransactionManager.Transaction normal = new TransactionManager.Transaction(normalName, 0, new Runnable() {
            @Override
            public void run() {
                LogUtil.d("1: thread:" + Thread.currentThread().getId() + new Date().toString());
            }
        });

        String timeName = "testTimeTransaction";
        TransactionManager.Transaction time = new TransactionManager.Transaction(timeName, 3, 2, new Runnable() {
            @Override
            public void run() {
                LogUtil.d("2: thread:" + Thread.currentThread().getId() + new Date().toString());
            }
        });

        TransactionManager manager = TransactionManager.getInstance();
        manager.addTransaction(normal);
        manager.addTransaction(time);


        wait(null, 10);

        boolean exist = manager.existTransactionsForName(normalName);
        assertFalse(exist);
        exist = manager.existTransactionsForName(timeName);
        assertTrue(exist);
    }

}

@@ -838,24 +838,79 @@
 dRemove()%7B%0A%0A
+        final boolean%5B%5D executedTransaction = %7Bfalse%7D;%0A
         Stri
@@ -942,32 +942,32 @@
 alTransaction%22;%0A
-
         Transact
@@ -1209,32 +1209,79 @@
 ().toString());%0A
+                executedTransaction%5B0%5D = true;%0A
             %7D%0A  
@@ -1802,15 +1802,201 @@
 it(n
-ull, 10
+ew WaitConditional() %7B%0A            @Override%0A            public boolean shouldWait() %7B%0A                return executedTransaction%5B0%5D;%0A            %7D%0A        %7D, 60);%0A        %0A        wait(null, 2
 );%0A%0A

change transaction case