Add test examples using C++ API
This commit is contained in:
parent
8c988c8804
commit
04b4cb3fd4
|
@ -0,0 +1,118 @@
|
|||
#include "client.h"
|
||||
#include <pthread.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
using namespace std;
|
||||
#define tnum 4000
|
||||
bool correctness = true;
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
string int2string(int n)
|
||||
{
|
||||
string s;
|
||||
stringstream ss;
|
||||
ss<<n;
|
||||
ss>>s;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
struct MyThread_args{
|
||||
int num;
|
||||
string sparql;
|
||||
int rnum;
|
||||
};
|
||||
|
||||
void* MyThread_run(void* thread_args)
|
||||
{
|
||||
struct MyThread_args *args;
|
||||
args = (struct MyThread_args *)thread_args;
|
||||
CHttpClient hc;
|
||||
string res;
|
||||
int ret;
|
||||
ret = hc.Get("http://172.31.222.94:9000/?operation=query&format=json&sparql="+args->sparql,res);
|
||||
int m = 0;
|
||||
for(int i = 0; i<args->sparql.length(); ++i)
|
||||
{
|
||||
if(args->sparql[i]=='?')
|
||||
++m;
|
||||
if(args->sparql[i]=='{')
|
||||
break;
|
||||
}
|
||||
int n = 0;
|
||||
for(int i = 0; i<res.length(); ++i)
|
||||
{
|
||||
if(res[i]=='{')
|
||||
++n;
|
||||
}
|
||||
int Num = (n-3)/(m+1);
|
||||
//if(Num<=10)
|
||||
//{
|
||||
// ofstream f("result/"+int2string(args->num)+".txt");
|
||||
// f<<res<<endl;
|
||||
// f.close();
|
||||
//}
|
||||
|
||||
if(args->rnum != Num)
|
||||
correctness = false;
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int result[6] = {10, 14, 14, 199424, 33910, 1039};
|
||||
string* sparql = new string[6];
|
||||
sparql[0] = "select ?v0 where\
|
||||
{\
|
||||
?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/LanguagesOfBotswana> .\
|
||||
?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/LanguagesOfNamibia> .\
|
||||
?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Language> .\
|
||||
}";
|
||||
sparql[1] = "select ?v0 where\
|
||||
{\
|
||||
?v0 <http://dbpedia.org/ontology/associatedBand> <http://dbpedia.org/resource/LCD_Soundsystem> .\
|
||||
}";
|
||||
sparql[2] = "select ?v2 where\
|
||||
{\
|
||||
<http://dbpedia.org/resource/!!Destroy-Oh-Boy!!> <http://dbpedia.org/property/title> ?v2 .\
|
||||
}";
|
||||
sparql[3] = "select ?v0 ?v2 where\
|
||||
{\
|
||||
?v0 <http://dbpedia.org/ontology/activeYearsStartYear> ?v2 .\
|
||||
}";
|
||||
sparql[4] = "select ?v0 ?v1 ?v2 where\
|
||||
{\
|
||||
?v0 <http://dbpedia.org/property/dateOfBirth> ?v2 .\
|
||||
?v1 <http://dbpedia.org/property/genre> ?v2 .\
|
||||
}";
|
||||
sparql[5] = "select ?v0 ?v1 ?v2 ?v3 where\
|
||||
{\
|
||||
?v0 <http://dbpedia.org/property/familycolor> ?v1 .\
|
||||
?v0 <http://dbpedia.org/property/glotto> ?v2 .\
|
||||
?v0 <http://dbpedia.org/property/lc> ?v3 .\
|
||||
}";
|
||||
pthread_t qt[tnum];
|
||||
void *status;
|
||||
struct MyThread_args args[tnum];
|
||||
for(int i = 0;i<tnum;i++)
|
||||
{
|
||||
args[i].num=i;
|
||||
args[i].sparql=sparql[i%6];
|
||||
args[i].rnum=result[i%6];
|
||||
pthread_create(&qt[i],NULL,MyThread_run,(void *)&args[i]);
|
||||
}
|
||||
for(int i = 0;i<tnum;i++)
|
||||
{
|
||||
pthread_join(qt[i],&status);
|
||||
|
||||
}
|
||||
if(correctness == true)
|
||||
cout<< "The answers are correct!" <<endl;
|
||||
else
|
||||
cout<< "The answers exist errors!" <<endl;
|
||||
pthread_exit(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,11 +1,17 @@
|
|||
CC=g++ -std=c++11
|
||||
#CC=ccache g++
|
||||
all: example Benchmark
|
||||
Benchmark: Benchmark.o
|
||||
$(CC) -o Benchmark Benchmark.o -lcurl -L../lib -lclient -lpthread
|
||||
|
||||
example: example.o
|
||||
$(CC) -o example example.o -lcurl -L../lib -lclient
|
||||
|
||||
Benchmark.o: Benchmark.cpp
|
||||
$(CC) -c -I../ Benchmark.cpp -o Benchmark.o
|
||||
|
||||
example.o: example.cpp
|
||||
$(CC) -c -I../ example.cpp -o example.o
|
||||
|
||||
clean:
|
||||
rm -rf *.o example
|
||||
rm -rf *.o example Benchmark
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
//NOTICE: you need to use libcurl-devel for C++ to use HTTP client, please read client.cpp and client.h seriously
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "client.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
CHttpClient hc;
|
||||
string res;
|
||||
int ret;
|
||||
|
||||
//ret = hc.Get("http://172.31.222.94:9000/?operation=build&db_name=lubm&ds_path=data/LUBM_10.n3", res);
|
||||
//cout<<res<<endl;
|
||||
|
||||
//ret = hc.Get("http://172.31.222.94:9000/?operation=load&db_name=lubm", res);
|
||||
//cout<<res<<endl;
|
||||
int result[6] = {10, 14, 14, 199424, 33910, 1039};
|
||||
string* sparql = new string[6];
|
||||
sparql[0] = "select ?v0 where\
|
||||
{\
|
||||
?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/LanguagesOfBotswana> .\
|
||||
?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/LanguagesOfNamibia> .\
|
||||
?v0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Language> .\
|
||||
}";
|
||||
sparql[1] = "select ?v0 where\
|
||||
{\
|
||||
?v0 <http://dbpedia.org/ontology/associatedBand> <http://dbpedia.org/resource/LCD_Soundsystem> .\
|
||||
}";
|
||||
sparql[2] = "select ?v2 where\
|
||||
{\
|
||||
<http://dbpedia.org/resource/!!Destroy-Oh-Boy!!> <http://dbpedia.org/property/title> ?v2 .\
|
||||
}";
|
||||
sparql[3] = "select ?v0 ?v2 where\
|
||||
{\
|
||||
?v0 <http://dbpedia.org/ontology/activeYearsStartYear> ?v2 .\
|
||||
}";
|
||||
sparql[4] = "select ?v0 ?v1 ?v2 where\
|
||||
{\
|
||||
?v0 <http://dbpedia.org/property/dateOfBirth> ?v2 .\
|
||||
?v1 <http://dbpedia.org/property/genre> ?v2 .\
|
||||
}";
|
||||
sparql[5] = "select ?v0 ?v1 ?v2 ?v3 where\
|
||||
{\
|
||||
?v0 <http://dbpedia.org/property/familycolor> ?v1 .\
|
||||
?v0 <http://dbpedia.org/property/glotto> ?v2 .\
|
||||
?v0 <http://dbpedia.org/property/lc> ?v3 .\
|
||||
}";
|
||||
int tnum = 6;
|
||||
tnum = 3000;
|
||||
bool correctness = true;
|
||||
for(int i = 0; i < tnum; ++i)
|
||||
{
|
||||
ret = hc.Get("http://172.31.222.94:9000/?operation=query&format=json&sparql="+sparql[i%6],res);
|
||||
cout<< i <<endl;
|
||||
int m = 0;
|
||||
for(int ii = 0; ii<sparql[i%6].length(); ++ii)
|
||||
{
|
||||
if(sparql[i%6][ii] == '?')
|
||||
++m;
|
||||
if(sparql[i%6][ii] == '{')
|
||||
break;
|
||||
}
|
||||
int n = 0;
|
||||
for(int ii = 0; ii<res.length(); ++ii)
|
||||
{
|
||||
if(res[ii] == '{')
|
||||
++n;
|
||||
}
|
||||
int Num = (n-3)/(m+1);
|
||||
if(Num!=result[i%6])
|
||||
correctness =false;
|
||||
|
||||
}
|
||||
if (correctness == true)
|
||||
cout<< "The answers are correct!" <<endl;
|
||||
else
|
||||
cout<< "The answers exist errors!" <<endl;
|
||||
//ret = hc.Get("127.0.0.1:8080/query/data/ex0.sql", res);
|
||||
//cout<<res<<endl;
|
||||
|
||||
//ret = hc.Get("http://172.31.222.94:9000/?operation=monitor", res);
|
||||
//cout<<res<<endl;
|
||||
|
||||
//ret = hc.Get("http://172.31.222.94:9000/?operation=unload&db_name=lubm", res);
|
||||
//cout<<res<<endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue