summaryrefslogtreecommitdiff
path: root/TAO/tests/Client_Leaks/Client_Task.cpp
blob: 61d60e45ba1646b7cdafcdb7f9a579d51210e494 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// $Id$
//

#include "Client_Task.h"

ACE_RCSID(Client_Leaks, Client_Task, "$Id$")

Client_Task::Client_Task (Test::Process_Factory_ptr process_factory,
                          int iterations)
  : process_factory_ (Test::Process_Factory::_duplicate (process_factory))
  , iterations_ (iterations)
  , successful_calls_ (0)
{
}

int
Client_Task::successful_calls (void) const
{
  return this->successful_calls_;
}

int
Client_Task::svc (void)
{
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Starting client task\n"));
  ACE_DECLARE_NEW_CORBA_ENV;

  int successful_calls = 0;

  ACE_TRY
    {
      this->validate_connection (ACE_TRY_ENV);
      ACE_TRY_CHECK;

      for (int i = 0; i != this->iterations_; ++i)
        {
          int retval = this->one_iteration (ACE_TRY_ENV);
          ACE_TRY_CHECK;

          if (retval != 0)
            successful_calls++;

          if (i % 10 == 0)
            {
              ACE_DEBUG ((LM_DEBUG,
                          "(%P|%t) - Client_Task::svc %d / %d iterations\n",
                          i, this->iterations_));
            }
        }
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "Exception caught:");
      return -1;
    }
  ACE_ENDTRY;
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Client task finished\n"));

  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
  this->successful_calls_ += successful_calls;

  return 0;
}

void
Client_Task::validate_connection (CORBA::Environment &ACE_TRY_ENV)
{
  ACE_TRY
    {
      for (int i = 0; i != 100; ++i)
        {
          (void) this->process_factory_->_non_existent (ACE_TRY_ENV);
          ACE_TRY_CHECK;
        }
    }
  ACE_CATCH (CORBA::TRANSIENT, ex)
    {
      // Ignore transient exceptions
    }
  ACE_ENDTRY;
  ACE_CHECK;
}

int
Client_Task::one_iteration (CORBA::Environment &ACE_TRY_ENV)
{
  ACE_TRY
    {
      Test::Process_var process =
        this->process_factory_->create_new_process (ACE_TRY_ENV);
      ACE_TRY_CHECK;

      (void) process->get_process_id (ACE_TRY_ENV);
      ACE_TRY_CHECK;

      process->shutdown (ACE_TRY_ENV);
      ACE_TRY_CHECK;

      return 1;
    }
  ACE_CATCH(Test::Spawn_Failed, ignored)
    {
      // Ignore this exception, it is usually caused by a transient
      // condition
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "Exception caught:");
    }
  ACE_ENDTRY;

  return 0;
}