|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Circles - Bring cloud-users closer together. |
|
6
|
|
|
* |
|
7
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
8
|
|
|
* later. See the COPYING file. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Maxence Lange <[email protected]> |
|
11
|
|
|
* @copyright 2017 |
|
12
|
|
|
* @license GNU AGPL version 3 or any later version |
|
13
|
|
|
* |
|
14
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
15
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
16
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
17
|
|
|
* License, or (at your option) any later version. |
|
18
|
|
|
* |
|
19
|
|
|
* This program is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU Affero General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
25
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
namespace OCA\Circles\Command; |
|
31
|
|
|
|
|
32
|
|
|
use daita\MySmallPhpTools\Traits\TArrayTools; |
|
33
|
|
|
use Exception; |
|
34
|
|
|
use OC\Core\Command\Base; |
|
35
|
|
|
use OCA\Circles\Model\GlobalScale\GSEvent; |
|
36
|
|
|
use OCA\Circles\Service\ConfigService; |
|
37
|
|
|
use OCA\Circles\Service\GlobalScaleService; |
|
38
|
|
|
use OCA\Circles\Service\GSUpstreamService; |
|
39
|
|
|
use OCP\IL10N; |
|
40
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
41
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
42
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
43
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Class CirclesList |
|
48
|
|
|
* |
|
49
|
|
|
* @package OCA\Circles\Command |
|
50
|
|
|
*/ |
|
51
|
|
|
class CirclesTest extends Base { |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
use TArrayTools; |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** @var IL10N */ |
|
58
|
|
|
private $l10n; |
|
59
|
|
|
|
|
60
|
|
|
/** @var GlobalScaleService */ |
|
61
|
|
|
private $globalScaleService; |
|
62
|
|
|
|
|
63
|
|
|
/** @var GSUpstreamService */ |
|
64
|
|
|
private $gsUpstreamService; |
|
65
|
|
|
|
|
66
|
|
|
/** @var ConfigService */ |
|
67
|
|
|
private $configService; |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* CirclesList constructor. |
|
72
|
|
|
* |
|
73
|
|
|
* @param IL10N $l10n |
|
74
|
|
|
* @param GlobalScaleService $globalScaleService |
|
75
|
|
|
* @param GSUpstreamService $gsUpstreamService |
|
76
|
|
|
* @param ConfigService $configService |
|
77
|
|
|
*/ |
|
78
|
|
|
public function __construct( |
|
79
|
|
|
IL10N $l10n, GlobalScaleService $globalScaleService, GSUpstreamService $gsUpstreamService, |
|
80
|
|
|
ConfigService $configService |
|
81
|
|
|
) { |
|
82
|
|
|
parent::__construct(); |
|
83
|
|
|
|
|
84
|
|
|
$this->l10n = $l10n; |
|
85
|
|
|
$this->gsUpstreamService = $gsUpstreamService; |
|
86
|
|
|
$this->globalScaleService = $globalScaleService; |
|
87
|
|
|
$this->configService = $configService; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
protected function configure() { |
|
92
|
|
|
parent::configure(); |
|
93
|
|
|
$this->setName('circles:test') |
|
94
|
|
|
->setDescription('testing some features') |
|
95
|
|
|
->addArgument('local', InputArgument::OPTIONAL, 'testing with a specific local cloud id') |
|
96
|
|
|
->addOption('delay', 'd', InputOption::VALUE_REQUIRED, 'delay before checking result'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param InputInterface $input |
|
102
|
|
|
* @param OutputInterface $output |
|
103
|
|
|
* |
|
104
|
|
|
* @return int |
|
105
|
|
|
* @throws Exception |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int { |
|
108
|
|
|
if ($input->getArgument('local')) { |
|
109
|
|
|
define('TEMP_LOCAL_CLOUD_ID', $input->getArgument('local')); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
$delay = 5; |
|
113
|
|
|
if ($input->getOption('delay')) { |
|
114
|
|
|
$delay = (int)$input->getOption('delay'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$instances = |
|
118
|
|
|
array_merge([$this->configService->getLocalCloudId()], $this->globalScaleService->getInstances()); |
|
119
|
|
|
|
|
120
|
|
|
$test = new GSEvent(GSEvent::TEST, true, true); |
|
121
|
|
|
$test->setAsync(true); |
|
122
|
|
|
$wrapper = $this->gsUpstreamService->newEvent($test); |
|
123
|
|
|
|
|
124
|
|
|
$output->writeln('Async request is sent, now waiting ' . $delay . ' seconds'); |
|
125
|
|
|
sleep($delay); |
|
126
|
|
|
$output->writeln('Pause is over, checking results for ' . $wrapper->getToken()); |
|
127
|
|
|
|
|
128
|
|
|
$wrappers = $this->gsUpstreamService->getEventsByToken($wrapper->getToken()); |
|
129
|
|
|
|
|
130
|
|
|
$result = []; |
|
131
|
|
|
foreach ($wrappers as $wrapper) { |
|
132
|
|
|
$result[$wrapper->getInstance()] = $wrapper->getEvent(); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
foreach ($instances as $instance) { |
|
136
|
|
|
$output->write($instance . ' '); |
|
137
|
|
|
if (array_key_exists($instance, $result) |
|
138
|
|
|
&& $result[$instance]->getResult() |
|
139
|
|
|
->gInt('status') === 1) { |
|
140
|
|
|
$output->writeln('<info>ok</info>'); |
|
141
|
|
|
} else { |
|
142
|
|
|
$output->writeln('<error>fail</error>'); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return 0; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
|