summaryrefslogtreecommitdiff
path: root/cpp/demo/Freeze/backup/Client.cpp
blob: 1ad35f9eea14f41802ccf7903011a3aa66529cb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// **********************************************************************
//
// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#include <IntLongMap.h>
#include <IceUtil/Time.h>
#include <Freeze/Freeze.h>

using namespace std;

static void
testFailed(const char* expr, const char* file, unsigned int line)
{
    cout << "failed!" << endl;
    cout << file << ':' << line << ": assertion `" << expr << "' failed" << endl;
    abort();
}

#define test(ex) ((ex) ? ((void)0) : testFailed(#ex, __FILE__, __LINE__))

int
main(int argc, char* argv[])
{
    Ice::PropertiesPtr properties = Ice::createProperties();
    properties->load("config");

    Ice::CommunicatorPtr communicator = Ice::initializeWithProperties(argc, argv, properties);

    Freeze::ConnectionPtr connection = Freeze::createConnection(communicator, "backup");
    IntLongMap m(connection, "IntLongMap", true);
    
    const int size = 10000;

    if(m.size() == 0)
    {	
	cout << "********* Creating new map ***********" << endl;
	Freeze::TransactionHolder txHolder(connection);

	IceUtil::Time time = IceUtil::Time::now();
	IceUtil::Int64 ms = time.toMilliSeconds();

	for(int i = 0; i < size; ++i)
	{
	    m.insert(IntLongMap::value_type(i, ms));
	}
	txHolder.commit();
    }
   
    cout << "Updating map" << endl;

    for(;;)
    {
	int count = 0;

	Freeze::TransactionHolder txHolder(connection);
	IceUtil::Time time = IceUtil::Time::now();
	IceUtil::Int64 ms = time.toMilliSeconds();

	IntLongMap::iterator p = m.begin();
	IceUtil::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 << "Read " << IceUtil::Time::milliSeconds(oldMs).toString() << " in all records;" 
	     << " updating with " << time.toString() << " ... " << flush;
	  
	txHolder.commit();
	cout << "done" << endl;
	test(count == size);
    }

    connection->close();

    communicator->destroy();

    return EXIT_SUCCESS;
}