Skip to content

Commit

Permalink
Merge pull request #143 from longbai/ajust_host
Browse files Browse the repository at this point in the history
调整服务器host设置方式
  • Loading branch information
longbai committed Oct 10, 2015
2 parents 58aab36 + 333050c commit 4878a2c
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 277 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#Changelog

## 7.0.8 (2015-10-09)
## 7.0.8 (2015-10-10)

### 调整
### 修改
* android-async-http 最低版本要求 1.4.9, 为了兼容 Android 6.0 感谢 Haoxiqiang
* 升级SDK环境
* 默认http port 为80
* 首选dns server 改为 119.29.29.29
* 变更上传服务器地址设置方式
* 增加https支持

## 7.0.7.1 (2015-08-05)

Expand Down
57 changes: 48 additions & 9 deletions library/src/androidTest/java/com/qiniu/android/FormUploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;

import com.qiniu.android.common.ServiceAddress;
import com.qiniu.android.common.Zone;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.Configuration;
import com.qiniu.android.storage.UpCompletionHandler;
import com.qiniu.android.storage.UploadManager;
import com.qiniu.android.storage.UploadOptions;
import com.qiniu.android.storage.Zone;

import junit.framework.Assert;

Expand Down Expand Up @@ -50,7 +51,6 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
}
}, opt);


try {
signal.await(120, TimeUnit.SECONDS); // wait for callback
Assert.assertNotNull("timeout", info);
Expand All @@ -61,7 +61,6 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
Assert.assertTrue(info.toString(), info.isOK());
Assert.assertNotNull(info.reqId);
Assert.assertNotNull(resp);
Assert.assertEquals("/", info.path);
}

@SmallTest
Expand Down Expand Up @@ -95,7 +94,6 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
Assert.assertTrue(info.toString(), info.isOK());

Assert.assertNotNull(info.reqId);
Assert.assertEquals("/", info.path);
Assert.assertNotNull(resp);
Assert.assertEquals("Fqr0xh3cxeii2r7eDztILNmuqUNN", resp.optString("key", ""));
}
Expand Down Expand Up @@ -269,10 +267,12 @@ public void testNoComplete() {

@SmallTest
public void testIpBack() throws Throwable {

ServiceAddress s = new ServiceAddress("http://upwelcome.qiniu.com", Zone.zone0.up.backupIps);
Zone z = new Zone(s, Zone.zone0.upBackup);
Configuration c = new Configuration.Builder()
.zone(new Zone("upwelcome.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp, Zone.zone0.upIp2))
.zone(z)
.build();

UploadManager uploadManager2 = new UploadManager(c);
final String expectKey = "你好;\"\r\n\r\n\r\n";
Map<String, String> params = new HashMap<String, String>();
Expand Down Expand Up @@ -305,9 +305,10 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {

@SmallTest
public void testPortBackup() throws Throwable {
ServiceAddress s = new ServiceAddress("http://upload.qiniu.com:9999", null);
Zone z = new Zone(s, Zone.zone0.upBackup);
Configuration c = new Configuration.Builder()
.zone(new Zone("upload.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp, Zone.zone0.upIp2))
.upPort(9999)
.zone(z)
.build();
UploadManager uploadManager2 = new UploadManager(c);
final String expectKey = "你好;\"\r\n\r\n\r\n";
Expand Down Expand Up @@ -341,8 +342,10 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {

@SmallTest
public void testDnsHijacking() throws Throwable {
ServiceAddress s = new ServiceAddress("http://uphijacktest.qiniu.com", Zone.zone0.up.backupIps);
Zone z = new Zone(s, Zone.zone0.upBackup);
Configuration c = new Configuration.Builder()
.zone(new Zone("uphijacktest.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp, Zone.zone0.upIp2))
.zone(z)
.build();
UploadManager uploadManager2 = new UploadManager(c);
final String expectKey = "你好;\"\r\n\r\n\r\n";
Expand Down Expand Up @@ -373,4 +376,40 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
Assert.assertNotNull(info.reqId);
Assert.assertNotNull(resp);
}

@SmallTest
public void testHttps() throws Throwable {

final String expectKey = "你好;\"\r\n\r\n\r\n";
Map<String, String> params = new HashMap<String, String>();
params.put("x:foo", "fooval");
final UploadOptions opt = new UploadOptions(params, null, true, null, null);
ServiceAddress s = new ServiceAddress("https://up.qbox.me", null);
Zone z = new Zone(s, Zone.zone0.upBackup);
Configuration c = new Configuration.Builder()
.zone(z)
.build();
UploadManager uploadManager2 = new UploadManager(c);
uploadManager2.put("hello".getBytes(), expectKey, TestConfig.token, new UpCompletionHandler() {
public void complete(String k, ResponseInfo rinfo, JSONObject response) {
Log.i("qiniutest", k + rinfo);
key = k;
info = rinfo;
resp = response;
signal.countDown();
}
}, opt);


try {
signal.await(120, TimeUnit.SECONDS); // wait for callback
Assert.assertNotNull("timeout", info);
} catch (InterruptedException e) {
e.printStackTrace();
}
Assert.assertEquals(info.toString(), expectKey, key);
Assert.assertTrue(info.toString(), info.isOK());
Assert.assertNotNull(info.reqId);
Assert.assertNotNull(resp);
}
}
105 changes: 60 additions & 45 deletions library/src/androidTest/java/com/qiniu/android/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import org.json.JSONObject;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand All @@ -25,7 +27,15 @@ public class HttpTest extends InstrumentationTestCase {
final CountDownLatch signal = new CountDownLatch(1);
private HttpManager httpManager;
private ResponseInfo info;
private JSONObject resp;

private static URI newURI(String s) {
try {
return new URI(s);
} catch (URISyntaxException e) {
e.printStackTrace();
}
return null;
}

@Override
protected void setUp() throws Exception {
Expand All @@ -34,14 +44,14 @@ protected void setUp() throws Exception {

@SmallTest
public void testPost1() throws Throwable {
httpManager.postData("http://www.baidu.com", "hello".getBytes(), null, null, new CompletionHandler() {
httpManager.postData(newURI("http://www.baidu.com"), "hello".getBytes(), null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null, false);
}, null);

try {
signal.await(6000, TimeUnit.SECONDS); // wait for callback
Expand All @@ -54,14 +64,14 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
@SmallTest
public void testPost2() throws Throwable {

httpManager.postData("http://up.qiniu.com", "hello".getBytes(), null, null, new CompletionHandler() {
httpManager.postData(newURI("http://up.qiniu.com"), "hello".getBytes(), null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null, false);
}, null);

try {
signal.await(60, TimeUnit.SECONDS); // wait for callback
Expand All @@ -75,14 +85,15 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
public void testPost3() throws Throwable {
runTestOnUiThread(new Runnable() { // THIS IS THE KEY TO SUCCESS
public void run() {
httpManager.postData("http://httpbin.org/status/500", "hello".getBytes(), null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null, false);
httpManager.postData(newURI("http://httpbin.org/status/500"), "hello".getBytes(),
null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null);
}
});

Expand All @@ -99,14 +110,15 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
public void testPost4() throws Throwable {
runTestOnUiThread(new Runnable() { // THIS IS THE KEY TO SUCCESS
public void run() {
httpManager.postData("http://httpbin.org/status/418", "hello".getBytes(), null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null, false);
httpManager.postData(newURI("http://httpbin.org/status/418"), "hello".getBytes(),
null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null);
}
});

Expand All @@ -122,14 +134,15 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
@SmallTest
public void testPostNoDomain() throws Throwable {

httpManager.postData("http://no-domain.qiniu.com", "hello".getBytes(), null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null, false);
httpManager.postData(newURI("http://no-domain.qiniu.com"), "hello".getBytes(),
null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null);

try {
signal.await(60, TimeUnit.SECONDS); // wait for callback
Expand All @@ -143,14 +156,15 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
@SmallTest
public void testPostNoPort() throws Throwable {

httpManager.postData("http://up.qiniu.com:12345", "hello".getBytes(), null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null, false);
httpManager.postData(newURI("http://up.qiniu.com:12345"), "hello".getBytes(),
null, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null);

try {
signal.await(60, TimeUnit.SECONDS); // wait for callback
Expand All @@ -164,14 +178,15 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
@SmallTest
public void testPostIP() throws Throwable {
Header[] x = {new BasicHeader("Host", "www.qiniu.com")};
httpManager.postData("http://183.136.139.12/", "hello".getBytes(), x, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null, false);
httpManager.postData(newURI("http://183.136.139.12/"), "hello".getBytes(),
x, null, new CompletionHandler() {
@Override
public void complete(ResponseInfo rinfo, JSONObject response) {
Log.d("qiniutest", rinfo.toString());
info = rinfo;
signal.countDown();
}
}, null);

try {
signal.await(60, TimeUnit.SECONDS); // wait for callback
Expand Down
6 changes: 5 additions & 1 deletion library/src/androidTest/java/com/qiniu/android/PortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;

import com.qiniu.android.common.ServiceAddress;
import com.qiniu.android.common.Zone;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.Configuration;
import com.qiniu.android.storage.UpCompletionHandler;
Expand Down Expand Up @@ -33,7 +35,9 @@ public class PortTest extends InstrumentationTestCase {

@Override
protected void setUp() throws Exception {
Configuration config = new Configuration.Builder().upPort(8888).build();
ServiceAddress s1 = new ServiceAddress("http://upload.qiniu.com:8888");
Zone z = new Zone(s1, s1);
Configuration config = new Configuration.Builder().zone(z).build();
uploadManager = new UploadManager(config);
}

Expand Down
Loading

0 comments on commit 4878a2c

Please sign in to comment.