use of com.aliyuncs.fc.request.DeleteServiceRequest in project fc-java-sdk by aliyun.
the class FunctionComputeClientTest method cleanupService.
private void cleanupService(String serviceName) {
DeleteServiceRequest request = new DeleteServiceRequest(serviceName);
client.deleteService(request);
System.out.println("Service " + serviceName + " is deleted");
}
use of com.aliyuncs.fc.request.DeleteServiceRequest in project fc-java-sdk by aliyun.
the class FunctionComputeClientTest method testCreateFunctionSetZipFile.
@Test
public void testCreateFunctionSetZipFile() throws IOException {
createService(SERVICE_NAME);
// Create a function
CreateFunctionRequest createFuncReq = new CreateFunctionRequest(SERVICE_NAME);
createFuncReq.setFunctionName(FUNCTION_NAME);
createFuncReq.setDescription("Function for test");
createFuncReq.setMemorySize(128);
createFuncReq.setHandler("hello_world.handler");
createFuncReq.setRuntime("nodejs4.4");
// Setup code directory
String tmpDir = "/tmp/fc_test_" + UUID.randomUUID();
String funcFilePath = tmpDir + "/" + "hello_world.js";
new File(tmpDir).mkdir();
PrintWriter out = new PrintWriter(funcFilePath);
out.println("'use strict'; module.exports.handler = function(event, context, callback) {console.log('hello world'); callback(null, 'hello world');};");
out.close();
String zipFilePath = tmpDir + "/" + "hello_world.zip";
ZipUtils.zipDir(new File(tmpDir), zipFilePath);
File zipFile = new File(zipFilePath);
byte[] buffer = new byte[(int) zipFile.length()];
FileInputStream fis = new FileInputStream(zipFilePath);
fis.read(buffer);
fis.close();
Code code = new Code().setZipFile(buffer);
createFuncReq.setCode(code);
createFuncReq.setTimeout(10);
client.createFunction(createFuncReq);
// Invoke the function
InvokeFunctionRequest request = new InvokeFunctionRequest(SERVICE_NAME, FUNCTION_NAME);
InvokeFunctionResponse response = client.invokeFunction(request);
assertEquals("hello world", new String(response.getContent()));
// Cleanups
client.deleteFunction(new DeleteFunctionRequest(SERVICE_NAME, FUNCTION_NAME));
client.deleteService(new DeleteServiceRequest(SERVICE_NAME));
new File(zipFilePath).delete();
new File(funcFilePath).delete();
new File(tmpDir).delete();
}
Aggregations