package com.qiniu.android.common;

import android.test.AndroidTestCase;
import android.util.Log;

import com.qiniu.android.TestConfig;
import com.qiniu.android.collect.LogHandler;

import junit.framework.Assert;

import java.util.concurrent.CountDownLatch;

/**
 * Created by long on 2016/9/30.
 */

public class AutoZoneTest extends AndroidTestCase {
    private String ak = TestConfig.ak;
    private String bkt = "javasdk";

//    public void testHttp() {
//        AutoZone zone = new AutoZone();
//        final CountDownLatch countDownLatch = new CountDownLatch(1);
//        zone.preQueryIndex(new AutoZone.ZoneIndex(ak, bkt), new Zone.QueryHandler() {
//            @Override
//            public void onSuccess() {
//                countDownLatch.countDown();
//            }
//
//            @Override
//            public void onFailure(int reason) {
//                countDownLatch.countDown();
//                fail();
//            }
//        });
//        try {
//            countDownLatch.await();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        ZoneInfo zoneInfo = zone.zoneInfo(ak, bkt);
//
////        assertTrue(zoneInfo.upDomainsList.contains("upload.qiniup.com"));
////        assertTrue(zoneInfo.upDomainsList.contains("up.qiniup.com"));
////        assertTrue(zoneInfo.upDomainsList.contains("upload-nb.qiniup.com"));
//    }

    public void testHttpFail() {
        AutoZone zone = new AutoZone();
        ZoneInfo zoneInfo = zone.zoneInfo(ak + "_not_be_ak", bkt);
        assertNull(zoneInfo);
    }

//    public void testSplitE() {
//        String s1 = "bkt:key";
//        String s2 = "bkt";
//        Assert.assertEquals(s1.split(":")[0], s2.split(":")[0]);
//    }

    public void testUCServer(){
        String ucServer = "ucserver.test";
        AutoZone autoZone = new AutoZone();
        autoZone.setUcServer(ucServer);
        assertTrue(autoZone.getUcServer() == ucServer);
    }

    public void testC1() {
        AutoZone autoZone = new AutoZone();
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        LogHandler logHandler = new LogHandler() {
            @Override
            public void send(String key, Object value) {
                //logHandler == null时，创建一个新的logHandler，防止调用send方法时报空指针，这里不处理数据
            }

            @Override
            public Object getUploadInfo() {
                return null;
            }
        };
        autoZone.preQueryIndex(logHandler, new AutoZone.ZoneIndex(ak, bkt), new Zone.QueryHandler() {
            @Override
            public void onSuccess() {
                countDownLatch.countDown();
            }

            @Override
            public void onFailure(int reason) {
                countDownLatch.countDown();
                fail(reason + "");
            }
        });
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        ZoneInfo info = autoZone.zoneInfo(ak, bkt);

        ZoneInfo info2 = autoZone.zoneInfo(ak, bkt);
        Assert.assertSame(info, info2);

    }

}

@@ -2853,16 +2853,112 @@
     %7D);%0A
+%0A        boolean wait = true;%0A        while (wait)%7B%0A%0A            wait = false;%0A            %0A    
         
@@ -2963,16 +2963,20 @@
   try %7B%0A
+    
         
@@ -3003,32 +3003,36 @@
 wait();%0A        
+    
 %7D catch (Interru
@@ -3054,32 +3054,36 @@
 ) %7B%0A            
+ 
+   
 e.printStackTrac
@@ -3083,24 +3083,67 @@
 ackTrace();%0A
+                wait = true;%0A            %7D%0A
         %7D%0A  
@@ -3132,32 +3132,33 @@
     %7D%0A        %7D%0A
+%0A
         ZoneInfo
@@ -3193,17 +3193,16 @@
 , bkt);%0A
-%0A
         
@@ -3246,24 +3246,24 @@
 , bkt);%0A
+
         
 Assert.a
@@ -3250,31 +3250,24 @@
 t);%0A        
-Assert.
 assertSame(i

change zone test case