public function testGetHostnameWithModuleVersionAndStringInstance()
 {
     $req = new GetHostnameRequest();
     $resp = new GetHostnameResponse();
     $req->setModule('module1');
     $req->setVersion('v1');
     $req->setInstance('73');
     $resp->setHostname('hostname');
     $this->apiProxyMock->expectCall('modules', 'GetHostname', $req, $resp);
     $this->assertEquals('hostname', ModulesService::getHostname('module1', 'v1', '73'));
     $this->apiProxyMock->verify();
 }
Esempio n. 2
0
 /**
  * Returns the hostname to use when contacting a module.
  * *
  * @param string $module The name of the module whose hostname should be
  * returned. If null then the hostname of the current module will be returned.
  *
  * @param string $version The version of the module whose hostname should be
  * returned. If null then the hostname for the version of the current
  * instance will be returned.
  *
  * @param string $instance The instance whose hostname should be returned. If
  * null then the load balanced hostname for the module will be returned. If
  * the module is not a fixed module then the instance parameter is ignored.
  *
  * @return string The valid canonical hostname that can be used to communicate
  * with the given module/version/instance e.g.
  * "0.version1.module5.myapp.appspot.com".
  * @throws \InvalidArgumentException If $module or $version is not a string
  * or if $instance is not a string or integer.
  * @throws ModulesException if the given combination of $module and $instance
  * is invalid.
  */
 public static function getHostname($module = null, $version = null, $instance = null)
 {
     $req = new GetHostnameRequest();
     $resp = new GetHostnameResponse();
     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);
     }
     if ($instance !== null) {
         if (!is_int($instance) && !is_string($instance)) {
             throw new \InvalidArgumentException('$instance must be an integer or string. Actual type: ' . gettype($instance));
         }
         $req->setInstance((string) $instance);
     }
     try {
         ApiProxy::makeSyncCall('modules', 'GetHostname', $req, $resp);
     } catch (ApplicationError $e) {
         throw self::errorCodeToException($e->getApplicationError());
     }
     return $resp->getHostname();
 }