public function testGetNumInstancesWithModuleAndVersion()
 {
     $req = new GetNumInstancesRequest();
     $resp = new GetNumInstancesResponse();
     $req->setModule('module1');
     $req->setVersion('v1');
     $resp->setInstances(3);
     $this->apiProxyMock->expectCall('modules', 'GetNumInstances', $req, $resp);
     $this->assertEquals(3, ModulesService::getNumInstances('module1', 'v1'));
     $this->apiProxyMock->verify();
 }
Ejemplo n.º 2
0
 /**
  * Get the number of instances set for a version of a module.
  *
  * This function does not work on automatically-scaled modules.
  *
  * @param string $module The name of the module to retrieve the count for. If
  * null then the count for the current module will be retrieved.
  *
  * @param string $version The version of the module to retrieve the count for.
  * If null then the count for the version of the current instance will be
  * retrieved.
  *
  * @return integer The number of instances set for the current module
  * version.
  *
  * @throws \InvalidArgumentException If $module or $version is not a string.
  * @throws ModulesException if the given combination of $module and $version
  * is invalid.
  */
 public static function getNumInstances($module = null, $version = null)
 {
     $req = new GetNumInstancesRequest();
     $resp = new GetNumInstancesResponse();
     if ($module !== null) {
         if (!is_string($module)) {
             throw new \InvalidArgumentException('$module must be a string. Actual type: ' . gettype($module));
         }
         $req->setModule($module);
     }
     if ($version !== null) {
         if (!is_string($version)) {
             throw new \InvalidArgumentException('$version must be a string. Actual type: ' . gettype($version));
         }
         $req->setVersion($version);
     }
     try {
         ApiProxy::makeSyncCall('modules', 'GetNumInstances', $req, $resp);
     } catch (ApplicationError $e) {
         throw self::errorCodeToException($e->getApplicationError());
     }
     return (int) $resp->getInstances();
 }