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