Ejemplo n.º 1
0
int TableSelectorTest()
{
	Table* table;
	// select all user where name starts with 'd'
	TableSelector selector("user", "d");
	
	table = database.GetTable("test");

	// populate table with test data
	table->Set(NULL, "user:1", "dopey");
	table->Set(NULL, "user:2", "grumpy");
	table->Set(NULL, "user:3", "doc");
	table->Set(NULL, "user:4", "happy");
	table->Set(NULL, "user:5", "bashful");
	table->Set(NULL, "user:6", "sneezy");
	table->Set(NULL, "user:7", "sleepy");
	
	table->Visit(selector);
	
	return TEST_SUCCESS;
	
}
Ejemplo n.º 2
0
int DatabaseSetTest(TestConfig& conf)
{
	int			numTest;
	Stopwatch	sw;
	Table*		table;
	Transaction* tx;
	bool		ret;
	int			limit = 16*KB;
	int			sum;

	if (conf.argc < 5)
	{
		Log_Message("\n\tusage: %s <keySize> <valueSize>", conf.typeString);
		return 1;
	}
	
	Log_SetTrace(true);
	
	if (DatabaseSetup())
	{
		Log_Message("Cannot initialize database!", 1);
		return 1;
	}
	
	table = database.GetTable("keyspace");
	if (!table)
	{
		Log_Message("Cannot initialize table!", 1);
		return 1;
	}
	
	conf.SetKeySize(atoi(conf.argv[3]));
	conf.SetValueSize(atoi(conf.argv[4]));

	Log_Message("Test type = %s, keySize = %d, valueSize = %d",
			conf.typeString, conf.keySize, conf.valueSize);
	
	tx = NULL;
	tx = new Transaction(table);
	sw.Start();
	tx->Begin();
	sw.Stop();
	
	sum = 0;
	numTest = conf.datasetTotal / conf.valueSize;
	for (int i = 0; i < numTest; i++)
	{
		if (conf.rndkey)
			GenRandomString(conf.key, conf.keySize);
		else
			conf.key.Writef("key%B:%d", conf.padding.length, conf.padding.buffer, i);
		
		sw.Start();
		ret = table->Set(tx, conf.key, conf.value);
		sw.Stop();
		if (!ret)
		{
			Log_Message("Test failed, ret = %s (%s failed after %d)", ret ? "true" : "false", conf.typeString, i);
			return 1;
		}
		
		sum += conf.keySize + conf.valueSize;
		if (sum > limit)
		{			
			sw.Start();
			tx->Commit();
			sw.Stop();
			
			double mbps = sum / (sw.elapsed / 1000.0) / 1000000;
			Log_Message("num = %d, elapsed = %ld, thruput = %lf MB/s", i, sw.elapsed, mbps);
			sw.Reset();
			
			sw.Start();
			tx->Begin();
			sw.Stop();

			sum = 0;
		}
	}

	sw.Start();
	tx->Commit();
	sw.Stop();

	double mbps = (conf.valueSize + conf.keySize) * numTest / (sw.elapsed / 1000.0) / 1000000;
	Log_Message("Test succeeded, %s/sec = %lf (num = %d, elapsed = %ld, thruput = %lf MB/s)", conf.typeString, numTest / (sw.elapsed / 1000.0), numTest, sw.elapsed, mbps);
	
	return 0;
}
Ejemplo n.º 3
0
int DatabaseSetTest(TestConfig& conf)
{
	int			numTest;
	Table*		table;
	Transaction* tx;
	bool		ret;
	int			limit = 16*KB;
	int			sum;
    char        lacKee[20];

	if (DatabaseSetup())
	{
		//Log_Message("Cannot initialize database!", 1);
		return 1;
	}

	table = database.GetTable("keyspace");
	if (!table)
	{
		//Log_Message("Cannot initialize table!", 1);
		return 1;
	}

	tx = NULL;
	tx = new Transaction(table);
	tx->Begin();

	sum = 0;
	numTest = conf.datasetTotal / conf.valueSize;
	for (int i = 0; i < numTest; i++)
	{
//##		if (conf.rndkey)
//##			GenRandomString(conf.key, conf.keySize);
//##		else
        conf.key.append("key");
        snprintf(lacKee, sizeof(lacKee), "%d", conf.padding.length());
        conf.key.append(lacKee);
        conf.key.append(conf.padding.c_str());
        snprintf(lacKee, sizeof(lacKee), "%d", i);
        conf.key.append(lacKee);

//			conf.key.Writef("key%B:%d", conf.padding.length, conf.padding.buffer, i);

		ret = table->Set(tx, conf.key.c_str(), conf.value.c_str());
		if (!ret)
		{
			//Log_Message("Test failed, ret = %s (%s failed after %d)", ret ? "true" : "false", conf.typeString, i);
			return 1;
		}

		sum += conf.keySize + conf.valueSize;
		if (sum > limit)
		{
			tx->Commit();


			tx->Begin();

			sum = 0;
		}
	}

	tx->Commit();


	return 0;
}
Ejemplo n.º 4
0
SymbolTable::SymbolTable(string file_name) {
	file = file_name;

	ifstream fin(file.c_str());
	ofstream fout("data/symbol_table.txt");
	Symbol symbol = Symbol(file);
	Table table[ symbol.GetCount() ];

	string line;
	int count = 0;
	int level_max = 0;
	/*------temp save for table------*/
	int level = 0;
	string symbol_name = "";
	string type_name = "";
	bool array_bool = false;
	bool function_bool = false;

	Origin();

	while(getline(fin, line)) {
		istringstream fin_word(line);
		string word = "";
		string remain = "";
		int pos = 0;

		while(fin_word >> word) {
			while(word != "") {
				if((pos = Check(word)) != -1) {
					if(pos != 0) {
						remain = word.substr(pos);
						word = word.substr(0, pos);
					}
					else {
						remain = word.substr(pos + length(word));
						word = word.substr(0, length(word));
					}
				}

				/*-----save in table------*/
				if( FindKeyWord(word) ) {
					type_name = word;
				}
				else {
					if(type_name != "") {
						if(word == ";" || word == "," || word == ")" || word == "=" || word == "(" || word == "[") {
							if(word == ";" || word == "," || word == ")" || word == "=") {
								array_bool = false;
								function_bool = false;
							}
							else if(word == "(") {
								level = 0;
								array_bool = false;
								function_bool = true;
							}
							else if(word == "[") {
								array_bool = true;
								function_bool = false;
							}

							table[count].Set(level, symbol_name, type_name, array_bool, function_bool);
							count = count + 1;
							type_name = "";
						}
						else {
							symbol_name = word;
						}
					}
				}

				if(word == "{" || word == "(") {
					level = level + 1;
				}
				else if(word == ")") {
					level = level - 1;
				}

				if(level > level_max) {
					level_max = level;
				}
				/*------------------------*/

				pos = 0;
				word = remain;
				remain = "";
			}
		}
	}

	int level_temp = 0;
	while(level_temp <= level_max) {
		for(int i = 0; i < (sizeof(table)/sizeof(*table)); i++) {
			if(table[i].GetLevel() == level_temp) {
				if(table[i].GetLevel() == table[i - 1].GetLevel() + 1) {
					scope = scope + 1;
				}
					table[i].SetScope(scope);
			}
		}

		level_temp = level_temp + 1;
	}

	//sort table
	for(int i = 0; i < (sizeof(table)/sizeof(*table)); i++) {
		for(int j = i + 1; j < (sizeof(table)/sizeof(*table)); j++) {
			if(table[j].GetScope() < table[i].GetScope()) {
				Table temp = Table();
				temp.Set(table[j].GetLevel(), table[j].GetSymbol(), table[j].GetType(), table[j].GetArray(), table[j].GetFunction());
				temp.SetScope(table[j].GetScope());

				for(int k = j; k >= i + 1; k--) {
					table[k].Set(table[k - 1].GetLevel(), table[k - 1].GetSymbol(), table[k - 1].GetType(), table[k - 1].GetArray(), table[k - 1].GetFunction());
					table[k].SetScope(table[k - 1].GetScope());
				}

				table[i].Set(temp.GetLevel(), temp.GetSymbol(), temp.GetType(), temp.GetArray(), temp.GetFunction());
				table[i].SetScope(temp.GetScope());
			}
		}
	}

	int temp = 0;
	for(int i = 0; i < (sizeof(table)/sizeof(*table)); i++) {
		if(temp != table[i].GetScope()) {
			temp = table[i].GetScope();
			fout << endl;
		}

		fout << table[i].GetScope() << " ";
		fout << table[i].GetSymbol() << " ";
		fout << table[i].GetType() << " ";
		fout << (table[i].GetArray() ? "true" : "false") << " ";
		fout << (table[i].GetFunction() ? "true" : "false") << " ";
		fout << endl;
	}

	fin.close();
	fout.close();
}