Search in sources :

Example 16 with TransformRequest

use of com.thinkbiganalytics.spark.rest.model.TransformRequest in project kylo by Teradata.

the class FileMetadataTest method setup.

private void setup() {
    this.trackerService = Mockito.spy(new FileMetadataTaskService());
    this.sparkShellUserProcessService = new MockSparkShellUserProcessService("tester");
    trackerService.setSparkShellUserProcessService(this.sparkShellUserProcessService);
    restClient = Mockito.mock(SparkShellRestClient.class);
    trackerService.setRestClient(restClient);
    Mockito.doReturn("tester").when(this.trackerService).getUsername();
    // Mockito.doCallRealMethod().when(this.trackerService).runScript(Mockito.any(ModifiedTransformResponse.class),Mockito.any());
    // Mockito.doCallRealMethod().when(this.trackerService).get(Mockito.anyString());
    // Mockito.doCallRealMethod().when(this.trackerService).removeFromCache(Mockito.anyString());
    Mockito.when(restClient.transform(Mockito.any(), Mockito.any())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            TransformRequest r = invocationOnMock.getArgumentAt(1, TransformRequest.class);
            TransformResponse response = new TransformResponse();
            response.setStatus(TransformResponse.Status.PENDING);
            response.setTable(UUID.randomUUID().toString());
            requestTracker.put(response.getTable(), new AtomicInteger(3));
            return response;
        }
    });
    Mockito.when(restClient.getTransformResult(Mockito.any(), Mockito.any())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            String tableId = invocationOnMock.getArgumentAt(1, String.class);
            AtomicInteger i = requestTracker.get(tableId);
            if (i != null) {
                int i1 = i.decrementAndGet();
                if (i1 == 0) {
                    TransformResponse response = new TransformResponse();
                    response.setStatus(TransformResponse.Status.SUCCESS);
                    response.setTable(tableId);
                    response.setResults(headerResult());
                    return Optional.of(response);
                } else {
                    // return pending
                    TransformResponse response = new TransformResponse();
                    response.setTable(tableId);
                    response.setStatus(TransformResponse.Status.PENDING);
                    return Optional.of(response);
                }
            }
            FileMetadataCompletionTask finalResult = trackerService.get(tableId);
            if (finalResult != null) {
                return Optional.of(finalResult.getModifiedTransformResponse());
            } else {
                // return pending
                TransformResponse response = new TransformResponse();
                response.setStatus(TransformResponse.Status.PENDING);
                response.setTable(tableId);
                requestTracker.put(response.getTable(), new AtomicInteger(3));
                return Optional.of(response);
            }
        }
    });
}
Also used : SparkShellRestClient(com.thinkbiganalytics.spark.shell.SparkShellRestClient) FileMetadataCompletionTask(com.thinkbiganalytics.spark.rest.filemetadata.tasks.FileMetadataCompletionTask) TransformRequest(com.thinkbiganalytics.spark.rest.model.TransformRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) ModifiedTransformResponse(com.thinkbiganalytics.spark.rest.model.ModifiedTransformResponse) FileMetadataTaskService(com.thinkbiganalytics.spark.rest.filemetadata.tasks.FileMetadataTaskService)

Aggregations

TransformRequest (com.thinkbiganalytics.spark.rest.model.TransformRequest)16 TransformResponse (com.thinkbiganalytics.spark.rest.model.TransformResponse)10 Test (org.junit.Test)9 Response (javax.ws.rs.core.Response)5 KyloCatalogClientBuilder (com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClientBuilder)4 SparkContextService (com.thinkbiganalytics.spark.SparkContextService)4 SparkScriptEngine (com.thinkbiganalytics.spark.repl.SparkScriptEngine)4 InputStream (java.io.InputStream)4 DataSet (com.thinkbiganalytics.spark.DataSet)2 SaveResponse (com.thinkbiganalytics.spark.rest.model.SaveResponse)2 TransformService (com.thinkbiganalytics.spark.service.TransformService)2 SparkShellProcess (com.thinkbiganalytics.spark.shell.SparkShellProcess)2 List (java.util.List)2 SparkContext (org.apache.spark.SparkContext)2 StructType (org.apache.spark.sql.types.StructType)2 StorageLevel (org.apache.spark.storage.StorageLevel)2 NamedParam (scala.tools.nsc.interpreter.NamedParam)2 Response (com.jayway.restassured.response.Response)1 DataSet (com.thinkbiganalytics.kylo.catalog.rest.model.DataSet)1 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)1