diff options
author | unknown <joreland@mysql.com> | 2005-01-14 08:58:50 +0100 |
---|---|---|
committer | unknown <joreland@mysql.com> | 2005-01-14 08:58:50 +0100 |
commit | 3705bf9dfbbfc89a6961fb916fafc088e53b6ca6 (patch) | |
tree | 9d0e47cac0e5eff8a896717aff21eca572de183a /ndb/test/src | |
parent | ae9b0794910fa12895135402b88addd71ce5e2d4 (diff) | |
download | mariadb-git-3705bf9dfbbfc89a6961fb916fafc088e53b6ca6.tar.gz |
wl2240 - ndb - new testcase for validating startTransation with hint
ndb/include/ndbapi/NdbDictionary.hpp:
NdbDictionaryColumn::getSizeInBytes
ndb/include/ndbapi/NdbOperation.hpp:
NdbOperation::getTable
ndb/include/ndbapi/NdbTransaction.hpp:
Make getConnectionNodeId public (for test programs)
ndb/include/util/Base64.hpp:
base64(void*)
ndb/src/common/util/Base64.cpp:
base64(void*)
ndb/src/kernel/blocks/ERROR_codes.txt:
New error code for REF'ing non-local TCKEYREQ
ndb/src/kernel/blocks/dbdih/DbdihMain.cpp:
Easy clearing of ERROR_INSERT
ndb/src/kernel/blocks/dbtc/DbtcMain.cpp:
New error code for REF'ing non-local TCKEYREQ
ndb/src/ndbapi/NdbDictionary.cpp:
NdbDictionaryColumn::getSizeInBytes
ndb/src/ndbapi/NdbDictionaryImpl.cpp:
If m_noIfDistKyes == 0, then each PK is dist key
ndb/src/ndbapi/NdbOperation.cpp:
NdbOperation::getTable
ndb/src/ndbapi/NdbOperationSearch.cpp:
remove d-key handling for pk ops
ndb/test/include/HugoCalculator.hpp:
remove unimpletemented methods
ndb/test/include/HugoOperations.hpp:
1) HugoOperation::setTransaction
2) Type independant value handling
3) Some more util methods
ndb/test/ndbapi/testPartitioning.cpp:
new testcase for validating startTransation with hint
ndb/test/run-test/atrt-mysql-test-run:
fix checks of return values
ndb/test/src/HugoCalculator.cpp:
Better generation of values
-- depends on fact that srand(K), rand() == srand(K), rand()
Generate string with base64
ndb/test/src/HugoOperations.cpp:
1) HugoOperation::setTransaction
2) Type independant value handling
3) Some more util methods
Diffstat (limited to 'ndb/test/src')
-rw-r--r-- | ndb/test/src/HugoCalculator.cpp | 253 | ||||
-rw-r--r-- | ndb/test/src/HugoOperations.cpp | 162 |
2 files changed, 171 insertions, 244 deletions
diff --git a/ndb/test/src/HugoCalculator.cpp b/ndb/test/src/HugoCalculator.cpp index 675d0ac786a..77821870754 100644 --- a/ndb/test/src/HugoCalculator.cpp +++ b/ndb/test/src/HugoCalculator.cpp @@ -16,6 +16,7 @@ #include "HugoCalculator.hpp" #include <NDBT.hpp> +#include <Base64.hpp> /* ************************************************************* * HugoCalculator @@ -58,22 +59,11 @@ Int32 HugoCalculator::calcValue(int record, int attrib, int updates) const { - const NdbDictionary::Column* attr = m_tab.getColumn(attrib); - // If this is the "id" column - if (attrib == m_idCol) - return record; - - // If this is the update column - if (attrib == m_updatesCol) - return updates; - - - Int32 val; - if (attr->getPrimaryKey()) - val = record + attrib; - else - val = record + attrib + updates; - return val; + + Int32 i; + calcValue(record, attrib, updates, (char*)&i, sizeof(i)); + + return i; } #if 0 HugoCalculator::U_Int32 calcValue(int record, int attrib, int updates) const; @@ -88,52 +78,100 @@ HugoCalculator::calcValue(int record, int updates, char* buf, int len) const { - const char a[26] = {"UAWBORCTDPEFQGNYHISJMKXLZ"}; + const NdbDictionary::Column* attr = m_tab.getColumn(attrib); - int val = calcValue(record, attrib, updates); - - if (attr->getPrimaryKey()){ - // Create a string where val is printed as chars in the beginning - // of the string, then fill with other chars - // The string length is set to the same size as the attribute - BaseString::snprintf(buf, len, "%d", val); - for(int i=strlen(buf); i < len; i++) - buf[i] = a[((val^i)%25)]; - } else{ - - // Fill buf with some pattern so that we can detect - // anomalies in the area that we don't fill with chars - int i; - for (i = 0; i<len; i++) - buf[i] = ((i+2) % 255); + Uint32 val; + do + { + if (attrib == m_idCol) + { + *((Uint32*)buf)= record; + return buf; + } - // Calculate length of the string to create. We want the string - // length to be varied between max and min of this attribute. - if(attr->getType() == NdbDictionary::Column::Varchar) - len = val % (len + 1); - else - if((val % (len + 1)) == 0) - len = 0; + // If this is the update column + if (attrib == m_updatesCol) + { + *((Uint32*)buf)= updates; + return buf; + } - // If len == 0 return NULL if this is a nullable attribute - if (len == 0){ - if(attr->getNullable() == true) - return NULL; - else - len++; + if (attr->getPrimaryKey()) + { + srand(record + attrib + updates); + val = (record + attrib); } - for(i=0; i < len; i++) - buf[i] = a[((val^i)%25)]; - buf[len] = 0; - - if(attr->getType() == NdbDictionary::Column::Bit) + else { - Uint32 bits= attr->getLength(); - Uint32 pos = bits >> 5; - Uint32 size = bits & 31; - ((Uint32*)buf)[pos] &= ((1 << size) - 1); + srand(record + attrib + updates); + val = rand(); } + } while (0); + + if(attr->getNullable() && (((val >> 16) & 255) > 220)) + return NULL; + + memcpy(buf, &val, (len > 4 ? 4 : len)); + int pos= 4; + while(pos + 4 < len) + { + val= rand(); + memcpy(buf+pos, &val, 4); + pos++; + } + + if(pos < len) + { + val= rand(); + memcpy(buf+pos, &val, (len - pos)); + } + + switch(attr->getType()){ + case NdbDictionary::Column::Tinyint: + case NdbDictionary::Column::Tinyunsigned: + case NdbDictionary::Column::Smallint: + case NdbDictionary::Column::Smallunsigned: + case NdbDictionary::Column::Mediumint: + case NdbDictionary::Column::Mediumunsigned: + case NdbDictionary::Column::Int: + case NdbDictionary::Column::Unsigned: + case NdbDictionary::Column::Bigint: + case NdbDictionary::Column::Bigunsigned: + case NdbDictionary::Column::Float: + case NdbDictionary::Column::Double: + case NdbDictionary::Column::Decimal: + case NdbDictionary::Column::Binary: + case NdbDictionary::Column::Datetime: + case NdbDictionary::Column::Time: + case NdbDictionary::Column::Date: + break; + case NdbDictionary::Column::Bit: + { + Uint32 bits= attr->getLength(); + Uint32 tmp = bits >> 5; + Uint32 size = bits & 31; + ((Uint32*)buf)[tmp] &= ((1 << size) - 1); + break; } + case NdbDictionary::Column::Varbinary: + case NdbDictionary::Column::Varchar: + case NdbDictionary::Column::Text: + case NdbDictionary::Column::Char: + case NdbDictionary::Column::Longvarchar: + case NdbDictionary::Column::Longvarbinary: + { + BaseString tmp; + base64_encode(buf, len, tmp); + memcpy(buf, tmp.c_str(), len); + break; + } + case NdbDictionary::Column::Blob: + case NdbDictionary::Column::Undefined: + abort(); + break; + } + + return buf; } @@ -148,93 +186,40 @@ HugoCalculator::verifyRowValues(NDBT_ResultRow* const pRow) const{ // Check the values of each column for (int i = 0; i<m_tab.getNoOfColumns(); i++){ if (i != m_updatesCol && id != m_idCol) { - const NdbDictionary::Column* attr = m_tab.getColumn(i); - Uint32 len = attr->getLength(); - switch (attr->getType()){ - case NdbDictionary::Column::Bit: - len = 4 * ((len + 31) >> 5); - case NdbDictionary::Column::Char: - case NdbDictionary::Column::Varchar: - case NdbDictionary::Column::Binary: - case NdbDictionary::Column::Varbinary:{ - char* buf = new char[len+1]; - const char* res = calcValue(id, i, updates, buf, len); - if (res == NULL){ - if (!pRow->attributeStore(i)->isNULL()){ - g_err << "|- NULL ERROR: expected a NULL but the column was not null" << endl; - g_err << "|- The row: \"" << (*pRow) << "\"" << endl; - result = -1; - } - } else{ - if (memcmp(res, pRow->attributeStore(i)->aRef(), len) != 0){ - // if (memcmp(res, pRow->attributeStore(i)->aRef(), pRow->attributeStore(i)->getLength()) != 0){ - g_err << "Column: " << attr->getName() << endl; - const char* buf2 = pRow->attributeStore(i)->aRef(); - for (Uint32 j = 0; j < len; j++) + Uint32 len = attr->getSizeInBytes(); + char buf[8000]; + const char* res = calcValue(id, i, updates, buf, len); + if (res == NULL){ + if (!pRow->attributeStore(i)->isNULL()){ + g_err << "|- NULL ERROR: expected a NULL but the column was not null" << endl; + g_err << "|- The row: \"" << (*pRow) << "\"" << endl; + result = -1; + } + } else{ + if (memcmp(res, pRow->attributeStore(i)->aRef(), len) != 0){ + // if (memcmp(res, pRow->attributeStore(i)->aRef(), pRow->attributeStore(i)->getLength()) != 0){ + g_err << "Column: " << attr->getName() << endl; + const char* buf2 = pRow->attributeStore(i)->aRef(); + for (Uint32 j = 0; j < len; j++) + { + g_err << j << ":" << hex << (int)buf[j] << "[" << hex << (int)buf2[j] << "]"; + if (buf[j] != buf2[j]) { - g_err << j << ":" << hex << (int)buf[j] << "[" << hex << (int)buf2[j] << "]"; - if (buf[j] != buf2[j]) - { - g_err << "==>Match failed!"; - } - g_err << endl; + g_err << "==>Match failed!"; } g_err << endl; - g_err << "|- Invalid data found in attribute " << i << ": \"" - << pRow->attributeStore(i)->aRef() - << "\" != \"" << res << "\"" << endl - << "Length of expected=" << (unsigned)strlen(res) << endl - << "Lenght of read=" - << (unsigned)strlen(pRow->attributeStore(i)->aRef()) << endl; - g_err << "|- The row: \"" << (* pRow) << "\"" << endl; - result = -1; } - } - delete []buf; - } - break; - case NdbDictionary::Column::Int: - case NdbDictionary::Column::Unsigned:{ - Int32 cval = calcValue(id, i, updates); - Int32 val = pRow->attributeStore(i)->int32_value(); - if (val != cval){ - g_err << "|- Invalid data found: \"" << val << "\" != \"" - << cval << "\"" << endl; + g_err << endl; + g_err << "|- Invalid data found in attribute " << i << ": \"" + << pRow->attributeStore(i)->aRef() + << "\" != \"" << res << "\"" << endl + << "Length of expected=" << (unsigned)strlen(res) << endl + << "Lenght of read=" + << (unsigned)strlen(pRow->attributeStore(i)->aRef()) << endl; g_err << "|- The row: \"" << (* pRow) << "\"" << endl; result = -1; } - break; - } - case NdbDictionary::Column::Bigint: - case NdbDictionary::Column::Bigunsigned:{ - Uint64 cval = calcValue(id, i, updates); - Uint64 val = pRow->attributeStore(i)->u_64_value(); - if (val != cval){ - g_err << "|- Invalid data found: \"" << val << "\" != \"" - << cval << "\"" - << endl; - g_err << "|- The row: \"" << (* pRow) << "\"" << endl; - result = -1; - } - } - break; - case NdbDictionary::Column::Float:{ - float cval = calcValue(id, i, updates); - float val = pRow->attributeStore(i)->float_value(); - if (val != cval){ - g_err << "|- Invalid data found: \"" << val << "\" != \"" - << cval << "\"" << endl; - g_err << "|- The row: \"" << (* pRow) << "\"" << endl; - result = -1; - } - } - break; - case NdbDictionary::Column::Undefined: - default: - assert(0); - result = -1; - break; } } } diff --git a/ndb/test/src/HugoOperations.cpp b/ndb/test/src/HugoOperations.cpp index f670591fe9c..959db70ec2e 100644 --- a/ndb/test/src/HugoOperations.cpp +++ b/ndb/test/src/HugoOperations.cpp @@ -32,6 +32,19 @@ int HugoOperations::startTransaction(Ndb* pNdb){ return NDBT_OK; } +int HugoOperations::setTransaction(NdbTransaction* new_trans){ + + if (pTrans != NULL){ + ndbout << "HugoOperations::startTransaction, pTrans != NULL" << endl; + return NDBT_FAILED; + } + pTrans = new_trans; + if (pTrans == NULL) { + return NDBT_FAILED; + } + return NDBT_OK; +} + int HugoOperations::closeTransaction(Ndb* pNdb){ if (pTrans != NULL){ @@ -145,26 +158,33 @@ int HugoOperations::pkUpdateRecord(Ndb* pNdb, return NDBT_FAILED; } - // Define primary keys - for(a = 0; a<tab.getNoOfColumns(); a++){ - if (tab.getColumn(a)->getPrimaryKey() == true){ - if(equalForAttr(pOp, a, r+recordNo) != 0){ - ERR(pTrans->getNdbError()); - return NDBT_FAILED; - } - } + if(setValues(pOp, r+recordNo, updatesValue) != NDBT_OK) + { + return NDBT_FAILED; } - - // Define attributes to update - for(a = 0; a<tab.getNoOfColumns(); a++){ - if (tab.getColumn(a)->getPrimaryKey() == false){ - if(setValueForAttr(pOp, a, recordNo+r, updatesValue ) != 0){ - ERR(pTrans->getNdbError()); - return NDBT_FAILED; - } + } + return NDBT_OK; +} + +int +HugoOperations::setValues(NdbOperation* pOp, int rowId, int updateId) +{ + // Define primary keys + int a; + for(a = 0; a<tab.getNoOfColumns(); a++){ + if (tab.getColumn(a)->getPrimaryKey() == true){ + if(equalForAttr(pOp, a, rowId) != 0){ + ERR(pTrans->getNdbError()); + return NDBT_FAILED; } - } + } else { + if(setValueForAttr(pOp, a, rowId, updateId ) != 0){ + ERR(pTrans->getNdbError()); + return NDBT_FAILED; + } + } } + return NDBT_OK; } @@ -187,25 +207,10 @@ int HugoOperations::pkInsertRecord(Ndb* pNdb, return NDBT_FAILED; } - // Define primary keys - for(a = 0; a<tab.getNoOfColumns(); a++){ - if (tab.getColumn(a)->getPrimaryKey() == true){ - if(equalForAttr(pOp, a, r+recordNo) != 0){ - ERR(pTrans->getNdbError()); - return NDBT_FAILED; - } - } + if(setValues(pOp, r+recordNo, updatesValue) != NDBT_OK) + { + return NDBT_FAILED; } - - // Define attributes to update - for(a = 0; a<tab.getNoOfColumns(); a++){ - if (tab.getColumn(a)->getPrimaryKey() == false){ - if(setValueForAttr(pOp, a, recordNo+r, updatesValue ) != 0){ - ERR(pTrans->getNdbError()); - return NDBT_FAILED; - } - } - } } return NDBT_OK; } @@ -373,38 +378,11 @@ int HugoOperations::equalForAttr(NdbOperation* pOp, return NDBT_FAILED; } - int len = attr->getLength(); - switch (attr->getType()){ - case NdbDictionary::Column::Bit: - len = 4 * ((len + 31) >> 5); - case NdbDictionary::Column::Char: - case NdbDictionary::Column::Varchar: - case NdbDictionary::Column::Binary: - case NdbDictionary::Column::Varbinary:{ - char buf[8000]; - memset(buf, 0, sizeof(buf)); - check = pOp->equal( attr->getName(), - calc.calcValue(rowId, attrId, 0, buf, len)); - break; - } - case NdbDictionary::Column::Int: - check = pOp->equal( attr->getName(), (Int32)calc.calcValue(rowId, attrId, 0)); - break; - case NdbDictionary::Column::Unsigned: - check = pOp->equal( attr->getName(), (Uint32)calc.calcValue(rowId, attrId, 0)); - break; - case NdbDictionary::Column::Bigint: - check = pOp->equal( attr->getName(), (Int64)calc.calcValue(rowId, attrId, 0)); - break; - case NdbDictionary::Column::Bigunsigned: - check = pOp->equal( attr->getName(), (Uint64)calc.calcValue(rowId, attrId, 0)); - break; - case NdbDictionary::Column::Float: - g_info << "Float not allowed as PK value" << endl; - check = -1; - break; - } - return check; + int len = attr->getSizeInBytes(); + char buf[8000]; + memset(buf, 0, sizeof(buf)); + return pOp->equal( attr->getName(), + calc.calcValue(rowId, attrId, 0, buf, len)); } int HugoOperations::setValueForAttr(NdbOperation* pOp, @@ -414,47 +392,11 @@ int HugoOperations::setValueForAttr(NdbOperation* pOp, int check = -1; const NdbDictionary::Column* attr = tab.getColumn(attrId); - int len = attr->getLength(); - switch (attr->getType()){ - case NdbDictionary::Column::Bit: - len = 4 * ((len + 31) >> 5); - case NdbDictionary::Column::Char: - case NdbDictionary::Column::Varchar: - case NdbDictionary::Column::Binary: - case NdbDictionary::Column::Varbinary:{ - char buf[8000]; - check = pOp->setValue( attr->getName(), - calc.calcValue(rowId, attrId, updateId, buf, len)); - break; - } - case NdbDictionary::Column::Int:{ - Int32 val = calc.calcValue(rowId, attrId, updateId); - check = pOp->setValue( attr->getName(), val); - } - break; - case NdbDictionary::Column::Bigint:{ - Int64 val = calc.calcValue(rowId, attrId, updateId); - check = pOp->setValue( attr->getName(), - val); - } - break; - case NdbDictionary::Column::Unsigned:{ - Uint32 val = calc.calcValue(rowId, attrId, updateId); - check = pOp->setValue( attr->getName(), val); - } - break; - case NdbDictionary::Column::Bigunsigned:{ - Uint64 val = calc.calcValue(rowId, attrId, updateId); - check = pOp->setValue( attr->getName(), - val); - } - break; - case NdbDictionary::Column::Float: - check = pOp->setValue( attr->getName(), - (float)calc.calcValue(rowId, attrId, updateId)); - break; - } - return check; + int len = attr->getSizeInBytes(); + char buf[8000]; + memset(buf, 0, sizeof(buf)); + return pOp->setValue( attr->getName(), + calc.calcValue(rowId, attrId, updateId, buf, len)); } int @@ -470,7 +412,7 @@ HugoOperations::verifyUpdatesValue(int updatesValue, int _numRows){ result = NDBT_FAILED; continue; } - + if(calc.getUpdatesValue(rows[i]) != updatesValue){ result = NDBT_FAILED; g_err << "Invalid updates value for row " << i << endl @@ -480,7 +422,7 @@ HugoOperations::verifyUpdatesValue(int updatesValue, int _numRows){ continue; } } - + if(_numRows == 0){ g_err << "No rows -> Invalid updates value" << endl; return NDBT_FAILED; |