我正在使用jersey-test-framework-grizzly-1.19.4
测试Web服务。我偶尔会看到由于com.sun.jersey.test.framework.spi.container.TestContainerException: java.net.BindException: No free port within range
异常而导致测试失败。从源代码中,我看到Jersey始终使用端口9998来启动服务器套接字。当然,该端口可能被并行运行的其他测试占用。是否可以告诉泽西岛使用任意范围内的可用端口?
答案 0 :(得分:0)
您可以通过设置from google.oauth2 import service_account
import googleapiclient.discovery
SCOPES = ['https://www.googleapis.com/auth/cloud-platform']
SERVICE_ACCOUNT_FILE = 'credentials/credentials.json'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
cloudfunction = googleapiclient.discovery.build('cloudfunctions', 'v1', credentials=credentials)
path ="projects/your-project-name/locations/cloud-function-location/functions/name-of-cloud-function"
data = {"data": "A String"}
a=cloudfunction.projects().locations().functions().call(name=path, body=data).execute()
属性来指定自定义端口,该属性方便地声明为TestProperties.CONTAINER_PORT。该属性由initialisation上的jersey.config.test.container.port
读取。
自然地,必须在初始化JerseyTest
之前设置属性。