### Question:
ElasticsearchStorageEngine extends CommonsStorageEngine<Client> { @Override @TimerJ protected void insert(TableMetadata targetTable, Row row, boolean isNotExists, Connection<Client> connection) throws UnsupportedException, ExecutionException { if (isNotExists) { throw new UnsupportedException("Operation insert isNotExists: Not supported yet by ElasticSearch"); } IndexRequestBuilder indexRequestBuilder = createIndexRequest(targetTable, row, connection); indexRequestBuilder.execute().actionGet(); loggInsert(targetTable); } ElasticsearchStorageEngine(ConnectionHandler connectionHandler);   }### Answer:
@Test public void testInsertOne() throws UnsupportedException, ExecutionException { ClusterName clusterName = new ClusterName(CLUSTER_NAME); TableMetadata targetTable = new TableMetadata(tableName, options, columns, indexes, clusterRef, partitionKey, clusterKey); Row row = createRow(COLUMN_NAME, CELL_VALUE); IndexRequestBuilder indexRequestBuilder = mock(IndexRequestBuilder.class); when(indexRequestBuilderCreator.createIndexRequestBuilder(targetTable, client, row)) .thenReturn(indexRequestBuilder); ListenableActionFuture<IndexResponse> listenableActionFuture = mock(ListenableActionFuture.class); when(indexRequestBuilder.execute()).thenReturn(listenableActionFuture); boolean isNotExists = false; elasticsearchStorageEngine.insert(clusterName, targetTable, row, isNotExists); verify(listenableActionFuture, times(1)).actionGet(); }
@Test public void testInserBulk() throws UnsupportedException, ExecutionException, java.util.concurrent.ExecutionException, InterruptedException { ClusterName clusterName = new ClusterName(CLUSTER_NAME); TableMetadata targetTable = new TableMetadata(tableName, options, columns, indexes, clusterRef, partitionKey, clusterKey); Collection<Row> row = new ArrayList<>(); Row row1 = createRow(COLUMN_NAME, CELL_VALUE); row.add(row1); Row row2 = createRow(OTHER_ROW_NAME, OTHER_CELL_VALUE); row.add(row2); IndexRequestBuilder indexRequestBuilder1 = mock(IndexRequestBuilder.class); when(indexRequestBuilderCreator.createIndexRequestBuilder(targetTable, client, row1)) .thenReturn(indexRequestBuilder1); IndexRequestBuilder indexRequestBuilder2 = mock(IndexRequestBuilder.class); when(indexRequestBuilderCreator.createIndexRequestBuilder(targetTable, client, row2)) .thenReturn(indexRequestBuilder2); BulkResponse bulkResponse = mock(BulkResponse.class); when(bulkResponse.hasFailures()).thenReturn(false); ListenableActionFuture<BulkResponse> listenableActionFuture = mock(ListenableActionFuture.class); when(listenableActionFuture.actionGet()).thenReturn(bulkResponse); BulkRequestBuilder bulkRequesBuilder = mock(BulkRequestBuilder.class); when(bulkRequesBuilder.execute()).thenReturn(listenableActionFuture); when(client.prepareBulk()).thenReturn(bulkRequesBuilder); boolean isNotExists = false; elasticsearchStorageEngine.insert(clusterName, targetTable, row, isNotExists); verify(bulkRequesBuilder, times(1)).add(indexRequestBuilder1); verify(bulkRequesBuilder, times(1)).add(indexRequestBuilder2); verify(listenableActionFuture, times(1)).actionGet(); }
@Test public void testInsertOnePK() throws UnsupportedException, ExecutionException { ClusterName clusterName = new ClusterName(CLUSTER_NAME); partitionKey.add(new ColumnName(INDEX_NAME, TYPE_NAME, COLUMN_NAME)); TableMetadata targetTable = new TableMetadata(tableName, options, columns, indexes, clusterRef, partitionKey, clusterKey); Row row = createRow(COLUMN_NAME, CELL_VALUE); IndexRequestBuilder indexRequestBuilder = mock(IndexRequestBuilder.class); when(indexRequestBuilderCreator.createIndexRequestBuilder(targetTable, client, row)) .thenReturn(indexRequestBuilder); ListenableActionFuture<IndexResponse> listenableActionFuture = mock(ListenableActionFuture.class); when(indexRequestBuilder.execute()).thenReturn(listenableActionFuture); boolean isNotExists = false; elasticsearchStorageEngine.insert(clusterName, targetTable, row, isNotExists); verify(listenableActionFuture, times(1)).actionGet(); }