diff options
author | Bernard Normier <bernard@zeroc.com> | 2003-09-17 20:16:05 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2003-09-17 20:16:05 +0000 |
commit | 89617fda731f0d581adfe4519549843166111b10 (patch) | |
tree | 2f15570cc790d0782455c180db252769d03d2801 /cpp/demo/Freeze/backup/Client.cpp | |
parent | swap instead of assignment (a bit more efficient) (diff) | |
download | ice-89617fda731f0d581adfe4519549843166111b10.tar.bz2 ice-89617fda731f0d581adfe4519549843166111b10.tar.xz ice-89617fda731f0d581adfe4519549843166111b10.zip |
Added Freeze backup demo
Diffstat (limited to 'cpp/demo/Freeze/backup/Client.cpp')
-rw-r--r-- | cpp/demo/Freeze/backup/Client.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/cpp/demo/Freeze/backup/Client.cpp b/cpp/demo/Freeze/backup/Client.cpp new file mode 100644 index 00000000000..aa50d7b2ba6 --- /dev/null +++ b/cpp/demo/Freeze/backup/Client.cpp @@ -0,0 +1,102 @@ +// ********************************************************************** +// +// Copyright (c) 2003 +// ZeroC, Inc. +// Billerica, MA, USA +// +// All Rights Reserved. +// +// Ice is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License version 2 as published by +// the Free Software Foundation. +// +// ********************************************************************** + +#include <IntLongMap.h> +#include <IceUtil/Time.h> +#include <Freeze/Freeze.h> + +using namespace Freeze; +using namespace Ice; +using namespace IceUtil; +using namespace std; + + +static void +testFailed(const char* expr, const char* file, unsigned int line) +{ + std::cout << "failed!" << std::endl; + std::cout << file << ':' << line << ": assertion `" << expr << "' failed" << std::endl; + abort(); +} + +#define test(ex) ((ex) ? ((void)0) : testFailed(#ex, __FILE__, __LINE__)) + + + +int +main(int argc, char* argv[]) +{ + PropertiesPtr properties = Ice::createProperties(argc, argv); + properties->load("config"); + + CommunicatorPtr communicator = initializeWithProperties(argc, argv, properties); + + ConnectionPtr connection = createConnection(communicator, "db"); + IntLongMap m(connection, "IntLongMap", true); + + const size_t size = 10000; + + if(m.size() == 0) + { + cout << "********* Creating new map ***********" << endl; + TransactionHolder txHolder(connection); + + Time time = Time::now(); + Int64 ms = time.toMilliSeconds(); + + for(size_t i = 0; i < size; ++i) + { + m.insert(IntLongMap::value_type(i, ms)); + } + txHolder.commit(); + } + + cout << "Updating map" << endl; + + for(;;) + { + size_t count = 0; + + TransactionHolder txHolder(connection); + Time time = Time::now(); + Int64 ms = time.toMilliSeconds(); + + IntLongMap::iterator p = m.begin(); + Int64 oldMs = p->second; + do + { + if(p->second != oldMs) + { + cerr << "old time (ms) == " << oldMs << endl; + cerr << "current current (ms) == " << p->second << endl; + } + + test(p->second == oldMs); + p.set(ms); + count++; + } while(++p != m.end()); + + cout << "Switching from " << Time::milliSeconds(oldMs).toString() + << " to " << time.toString() << " ... " << flush; + + txHolder.commit(); + cout << "done" << endl; + test(count == size); + } + + connection->close(); + communicator->destroy(); + + return EXIT_SUCCESS; +} |