mysql常用操作速查

简介
mysql速查
net start MySQL服务名
net stop MySQL服务名

mysql -h主机名 -u用户名 [-P端口] -p
quit;或exit;

java多线程测试框架

 最近要对一个webservice接口做测试,需测试高并发接口是否会以异常数据返回,编写了如下demo,有类似需求的可以参考下。
 注意事项:
1,线程使用了callable接口形式,call相对runable接口有个好处是允许带有返回值。
2,线程需要的入参可以在初始化时带入。比如本例中的ListkeyList, ListtenantIdList,就是线程入参。
3,线程出参return 出来即可。使用线程提交到线程池submit时返回的future对象的get()方法可以取得线程的最终返回值,本例中future.get()取得的就是各个线程返回的genIDs的list对象。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.yuan.demo.multiThreadTest;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
* 多线程测试框架,可用来测试json接口,webservice接口,或一般性的httpclient客户端等
* 支持对线程传入参数以及取得线程返回值(此例子是list<string>,并且对返回值进行重复性的校验),
*
* @author yuan
* @version 1.0.0
*/
public class MultiThreadTest {
/**
* 程序总入口
*/
public static void main(String[] args) {
long millis_start = System.currentTimeMillis();
int threadNum = 5;
List<String> list = new ArrayList<String>();

//创建线程池
ExecutorService pool = Executors.newCachedThreadPool();

List<String> tenantIdList = new ArrayList<String>();
tenantIdList.add("000001");
tenantIdList.add("000011");
List<String> keyList = new ArrayList<String>();
keyList.add("STOCKID");
keyList.add("STOCKNAME");
for (int i = 0; i < threadNum; i++) {
Callable<List<String>> myThread = new CallThread(i, keyList, tenantIdList);
Future<List<String>> future = pool.submit(myThread);
try {
list.addAll(future.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
pool.shutdown();
Set<String> listSet = new HashSet<String>(list);
System.out.println("list_size:" + list.size() + " list_set_size:" + listSet.size());
if (list.size() != listSet.size()) {
System.out.println("数据有重复");
System.out.println("list:" + list);
System.out.println("listSet:" + listSet);
}else{
System.out.println("数据无重复");
}

long millis_end = System.currentTimeMillis();
System.out.println("总耗时(s):" + (millis_end - millis_start));
}

}

/**
* 可返回list<String>数据的线程,需要自己实现其中的call函数
*/
class CallThread implements Callable<List<String>> {
private int i; // 第几个线程
List<String> tenantIdList;
List<String> keyList;
List<String> genIDs = new ArrayList<String>();

/**
* 构造函数,可将任务依赖的变量传入
*
* @param keyList,任务依赖的变量
* @param tenantIdList,任务依赖的变量
* @return list<String>
*/
public CallThread(int i, List<String> keyList, List<String> tenantIdList) {
this.i = i;
this.keyList = keyList;
this.tenantIdList = tenantIdList;
}

public List<String> call() throws Exception {
for (int j = 0; j < this.keyList.size(); j++) {
for (int k = 0; k < this.tenantIdList.size(); k++) {
/*这里的yourdata实际可能为webservice接口的调用,或client的调用*/
String yourData = this.i+this.keyList.get(j) + this.tenantIdList.get(k);
genIDs.add(yourData);
}
}
return genIDs;
}
}

java常用代码速查

网络

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
URL相关
URLConnection使用代理:
URL url = new URL(purl);
SocketAddress add = new InetSocketAddress("110.4.12.170", 83);
Proxy p = new Proxy(Proxy.Type.HTTP, add);
URLConnection turl = url.openConnection(p);
turl.setConnectTimeout(urlTimeout);
turl.setReadTimeout(urlTimeout);
BufferedReader in = new BufferedReader(new InputStreamReader(turl.getInputStream(), charset));

socket相关
创建socket:st = new Socket(HOST, PORT);
构造输入输出流:BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(st
.getOutputStream()));
(读)写数据:bw.write(startConnection);
刷新缓冲区:bw.flush();
关闭缓冲区:bw.close();

servlet:
request.setCharacterEncoding("UTF-8");
String wechatid = request.getParameter("openID");//微信号
Map<String, String[]> tmpMap = request.getParameterMap();
response.setCharacterEncoding("UTF-8");
response.getOutputStream().write(errormsg.getBytes("UTF-8"));

网页内容读取URLConnection:
URL url = new URL(purl);
URLConnection turl = url.openConnection();
turl.setConnectTimeout(urlTimeout);
turl.setReadTimeout(urlTimeout);
BufferedReader in = new BufferedReader(new InputStreamReader(
turl.getInputStream()));

while ((line = in.readLine()) != null) {
content += line;
}
in.close();


httpclient文件发送:
Protocol myhttps = new Protocol("https",new MySecureProtocolSocketFactory(),443);
Protocol.registerProtocol("https", myhttps);//https需要
HttpClient httpclient=new HttpClient();

PostMethod filePost = new PostMethod("https://api.ffan.com/zhaofangbao/v1/bosera/upload");

//使用系统提供的默认的恢复策略
//filePost.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler());

String param = "verify=" + URLEncoder.encode("verifytest", "utf-8") + "&type=" + "1";
filePost.setQueryString(param);
String filepath = "D:\\工作文件夹\\工作文档\\filetest.txt";
File targetFile = new File(filepath);
Part parts[] = {new FilePart("file", targetFile) };
filePost.setRequestEntity(new MultipartRequestEntity(parts,filePost.getParams()));
httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(50000);
//执行PostMethod
int statusCode = httpclient.executeMethod(filePost);
System.out.println("thirdChannel batchFileUpload http status:" + statusCode);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: "+ filePost.getStatusLine());
}
//读取内容
byte[] responseBody = filePost.getResponseBody();
//处理内容
System.out.println(new String(responseBody,"UTF-8"));
TrustAnyTrustManager.java
MySecureProtocolSocketFactory.java
connect.java

参考文章:
http://blog.csdn.net/noodies/article/details/17240805
http://tc.chinawin.net/it/softwaredev/article-eaa5.html
http://www.91r.net/ask/7684654.html
http://blog.sina.com.cn/s/blog_74cef98a0101pl16.html
http://hougbin.iteye.com/blog/1196063

python之FFT快速傅里叶变换

本科小作业,快速傅里叶变换
python3.2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Copyright (C) 2011-2012 YuanJh
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""yuanJh's fft and ifft module.
the detail about fft you can see "http://en.wikipedia.org/wiki/Fast_Fourier_transform"
Main functions:
fft(a)
ifft(a)
"""
from math import *
from cmath import *
import sys
from numpy import *
pi=3.1414926

#version infomation
__version__ = '1.0'

#################### function recursive FFT ####################
def RECURSIVE_FFT(a):
"Use recursive method to realize FFT"
n=len(a)
if n==1:
return a
wn=complex(cos(-2*pi/n),sin(-2*pi/n)) #create the complex number wn=cos(-2pi/n)+sin(-2pi/n)i
w=1

a0=[]
a1=[]
for i in range(0,n-1,2):
a0.append(a[i]) #pick up the even number
a1.append(a[i+1]) #pick up the odd number

y0=RECURSIVE_FFT(a0) #translate the even part
y1=RECURSIVE_FFT(a1) #translate the odd part

y=[0 for i in range(n)]
for k in range(0,int(n/2)): #combine the even part and the odd part
y[k]=y0[k]+w*y1[k]
y[k+int(n/2)]=y0[k]-w*y1[k]
w*=wn
return y
#################### end function recursive FFT ####################

#################### function recursive IFFT ####################
def RECURSIVE_IFFT(a):
"Use recursive method to realize IFFT"
n=len(a)
if n==1:
return a
wn=complex(cos(2*pi/n),sin(2*pi/n)) #create the complex number wn=cos(2pi/n)+sin(2pi/n)i
w=1

a0=[]
a1=[]
for i in range(0,n-1,2):
a0.append(a[i]) #pick up the even number
a1.append(a[i+1]) #pick up the odd number

y0=RECURSIVE_IFFT(a0)
y1=RECURSIVE_IFFT(a1)

y=[0 for i in range(n)]
for k in range(0,int(n/2)): #combine the even part and the odd part
y[k]=y0[k]+w*y1[k]
y[k+int(n/2)]=y0[k]-w*y1[k]
w*=wn
return y
#################### end function recursive IFFT ####################

#################### got data and verify the program ####################
a=input("please input the number (use ',' split):")
a=a.split(',')
n=len(a)
#tempn=ceil(log2(n))
#tempn=tempn**2

for i in range(0,n):
a[i]=int(a[i])

#################### verify the FFT ####################
print ("the results of my program fft")
b=RECURSIVE_FFT(a)
for i in range(0,n):
print ("%4d: %4.4f+%4.4fi"%(a[i],b[i].real,b[i].imag))

print ("the results of the numpy program fft") #Use the function in the package numpy
b=fft.fft(a)
for i in range(0,n):
print ("%4d: %4.4f+%4.4fi"%(a[i],b[i].real,b[i].imag))

#################### verify the IFFT ####################
#test the my ifft program is right or not by compare with the ifft function in numpy package
print ("the results of my program ifft")
lenb=len(b)
a=RECURSIVE_IFFT(b)
for i in range(0,n):
print("%4.4f+%4.4fi: %4.4f+%4.4fi"%(b[i].real,b[i].imag,a[i].real/lenb,a[i].imag/lenb))

print ("the results of the numpy program ifft")
a=fft.ifft(b)
for i in range(0,n):
print("%4.4f+%4.4fi: %4.4f+%4.4fi"%(b[i].real,b[i].imag,a[i].real,a[i].imag))

文件名:fft.py
实现语言:PYTHON
1,系统概述
利用递归的方法实现快速傅里叶变化(FFT)和快速傅里叶逆变换(IFFT)。
2,模块层次
主要包含三部分:
1,递归实现快速傅里叶变换(FFT)。
2,快速傅里叶逆变换(IFFT)。
3,数据录入以及结果正确性验证。
3,函数声明表
def RECURSIVE_FFT(a):
功能说明:递归实现快速傅里叶变换。
参数说明:
a:需要进行快速傅里叶变换的数据,以列表(类似C,JAVA中数组)形式存储。
def RECURSIVE_IFFT(a):
功能说明:递归实现快速傅里叶逆变换,
参数说明:
a:需要进行快速傅里叶逆变换的数据,以列表(类似C,JAVA中数组)形式存储。

filename:fft.py
language:python
1,System overview
Using recursive method to realize Fast Fourier Transform (FFT) and inverse Fast Fourier Transform (IFFT).
2,Module and level
Mainly includes three parts:
1, The recursive Fast Fourier Transform(FFT).
2, Inverse Fast Fourier Transform(IFFT).
3, Got data and verify the results.
3,Function declaration table
def RECURSIVE_FFT (a):
Function introduction:recursive realize Fast Fourier Transform.
Parameters:
a: the data need for Fast Fourier Transform store as a list (similar to C, JAVA the array).
def RECURSIVE_IFFT (a):
Function introduction: recursive inverse Fast Fourier Transform.
Parameters:
a: the data need for inverse Fast Fourier Transform store as a list.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×