testProperties.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:5k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #include <ndb_global.h>
  14. #include "Properties.hpp"
  15. #include <NdbOut.hpp>
  16. #include "uucode.h"
  17. bool
  18. writeToFile(const Properties & p, const char * fname, bool uu = true){
  19.   Uint32 sz = p.getPackedSize();
  20.   char * buffer = (char*)malloc(sz);
  21.   
  22.   FILE * f = fopen(fname, "wb");
  23.   bool res = p.pack((Uint32*)buffer);
  24.   if(res != true){
  25.     ndbout << "Error packing" << endl;
  26.     ndbout << "p.getPropertiesErrno() = " << p.getPropertiesErrno() << endl;
  27.     ndbout << "p.getOSErrno()         = " << p.getOSErrno() << endl;
  28.   }
  29.   if(uu)
  30.     uuencode(buffer, sz, f);
  31.   else {
  32.     fwrite(buffer, 1, sz, f);
  33.   }
  34.       
  35.   fclose(f);
  36.   free(buffer);
  37.   return res;
  38. }
  39. bool
  40. readFromFile(Properties & p, const char *fname, bool uu = true){
  41.   Uint32 sz = 30000;
  42.   char * buffer = (char*)malloc(sz);
  43.   FILE * f = fopen(fname, "rb");
  44.   if(uu)
  45.     uudecode(f, buffer, sz);
  46.   else 
  47.     fread(buffer, 1, sz, f);
  48.   fclose(f);
  49.   bool res = p.unpack((Uint32*)buffer, sz);
  50.   if(res != true){
  51.     ndbout << "Error unpacking" << endl;
  52.     ndbout << "p.getPropertiesErrno() = " << p.getPropertiesErrno() << endl;
  53.     ndbout << "p.getOSErrno()         = " << p.getOSErrno() << endl;
  54.   }
  55.   free(buffer);
  56.   return res;
  57. }
  58. void putALot(Properties & tmp){
  59.   int i = 123;
  60.   tmp.put("LockPagesInMainMemory", i++);
  61.   tmp.put("SleepWhenIdle", i++);
  62.   tmp.put("NoOfSignalsToExecuteBetweenCommunicationInterfacePoll", i++);
  63.   tmp.put("TimeBetweenWatchDogCheck", i++);
  64.   tmp.put("StopOnError", i++);
  65.   
  66.   tmp.put("MaxNoOfConcurrentOperations", i++);
  67.   tmp.put("MaxNoOfConcurrentTransactions", i++);
  68.   tmp.put("MemorySpaceIndexes", i++);
  69.   tmp.put("MemorySpaceTuples", i++);
  70.   tmp.put("MemoryDiskPages", i++);
  71.   tmp.put("NoOfFreeDiskClusters", i++);
  72.   tmp.put("NoOfDiskClusters", i++);
  73.   
  74.   tmp.put("TimeToWaitAlive", i++);
  75.   tmp.put("HeartbeatIntervalDbDb", i++);
  76.   tmp.put("HeartbeatIntervalDbApi", i++);
  77.   tmp.put("TimeBetweenInactiveTransactionAbortCheck", i++);
  78.   
  79.   tmp.put("TimeBetweenLocalCheckpoints", i++);
  80.   tmp.put("TimeBetweenGlobalCheckpoints", i++);
  81.   tmp.put("NoOfFragmentLogFiles", i++);
  82.   tmp.put("NoOfConcurrentCheckpointsDuringRestart", i++);
  83.   tmp.put("TransactionInactiveTimeBeforeAbort", i++);
  84.   tmp.put("NoOfConcurrentProcessesHandleTakeover", i++);
  85.   
  86.   tmp.put("NoOfConcurrentCheckpointsAfterRestart", i++);
  87.   
  88.   tmp.put("NoOfDiskPagesToDiskDuringRestartTUP", i++);
  89.   tmp.put("NoOfDiskPagesToDiskAfterRestartTUP", i++);
  90.   tmp.put("NoOfDiskPagesToDiskDuringRestartACC", i++);
  91.   tmp.put("NoOfDiskPagesToDiskAfterRestartACC", i++);
  92.   
  93.   tmp.put("NoOfDiskClustersPerDiskFile", i++);
  94.   tmp.put("NoOfDiskFiles", i++);
  95.   // Always found
  96.   tmp.put("NoOfReplicas",      33);
  97.   tmp.put("MaxNoOfAttributes", 34);
  98.   tmp.put("MaxNoOfTables",     35);
  99. }
  100. int
  101. main(void){
  102.   Properties p;
  103.   p.put("Kalle", 1);
  104.   p.put("Ank1", "anka");
  105.   p.put("Ank2", "anka");
  106.   p.put("Ank3", "anka");
  107.   p.put("Ank4", "anka");
  108.   putALot(p);
  109.   Properties tmp;
  110.   tmp.put("Type", "TCP");
  111.   tmp.put("OwnNodeId", 1);
  112.   tmp.put("RemoteNodeId", 2);
  113.   tmp.put("OwnHostName", "local");
  114.   tmp.put("RemoteHostName", "remote");
  115.   
  116.   tmp.put("SendSignalId", 1);
  117.   tmp.put("Compression", (Uint32)false);
  118.   tmp.put("Checksum", 1);
  119.   
  120.   tmp.put64("SendBufferSize", 2000);
  121.   tmp.put64("MaxReceiveSize", 1000);
  122.   
  123.   tmp.put("PortNumber", 1233);
  124.   putALot(tmp);
  125.   p.put("Connection", 1, &tmp);
  126.   p.put("NoOfConnections", 2);
  127.   p.put("NoOfConnection2", 2);
  128.   p.put("kalle", 3);
  129.   p.put("anka", "kalle");
  130.   
  131.   Properties p2;
  132.   p2.put("kalle", "anka");
  133.   p.put("prop", &p2);
  134.   p.put("Connection", 2, &tmp);
  135.   p.put("Connection", 3, &tmp);
  136.   p.put("Connection", 4, &tmp);
  137.   /*
  138.   */
  139.   
  140.   Uint32 a = 99;
  141.   const char * b;
  142.   const Properties * p3;
  143.   Properties * p4;
  144.   
  145.   bool bb = p.get("kalle", &a);
  146.   bool cc = p.get("anka", &b);
  147.   bool dd = p.get("prop", &p3);
  148.   if(p.getCopy("prop", &p4))
  149.     delete p4;
  150.   
  151.   p2.put("p2", &p2);
  152.   
  153.   p.put("prop2", &p2);
  154.   /* */  
  155.   p.print(stdout, "testing 1: ");
  156.   
  157.   writeToFile(p, "A_1");
  158.   writeToFile(p, "B_1", false);
  159.   
  160.   Properties r1;
  161.   readFromFile(r1, "A_1");
  162.   writeToFile(r1, "A_3");
  163.   
  164.   //r1.print(stdout, "testing 2: ");
  165.   Properties r2;
  166.   readFromFile(r2, "A_1");
  167.   writeToFile(r2, "A_4");
  168.   
  169.   Properties r3;
  170.   readFromFile(r3, "B_1", false);
  171.   writeToFile(r3, "A_5");
  172.   r3.print(stdout, "testing 3: ");  
  173.   return 0;
  174. }