Search in sources :

Example 1 with CustomMatcher

use of org.hamcrest.CustomMatcher in project dubbo by alibaba.

the class DubboMonitorTest method testSum.

@Test
public void testSum() {
    URL statistics = new URLBuilder(DUBBO_PROTOCOL, "10.20.153.11", 0).addParameter(MonitorService.APPLICATION, "morgan").addParameter(MonitorService.INTERFACE, "MemberService").addParameter(MonitorService.METHOD, "findPerson").addParameter(MonitorService.CONSUMER, "10.20.153.11").addParameter(MonitorService.SUCCESS, 1).addParameter(MonitorService.FAILURE, 0).addParameter(MonitorService.ELAPSED, 3).addParameter(MonitorService.MAX_ELAPSED, 3).addParameter(MonitorService.CONCURRENT, 1).addParameter(MonitorService.MAX_CONCURRENT, 1).build();
    Invoker invoker = mock(Invoker.class);
    MonitorService monitorService = mock(MonitorService.class);
    given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:7070?interval=20"));
    DubboMonitor dubboMonitor = new DubboMonitor(invoker, monitorService);
    dubboMonitor.collect(statistics);
    dubboMonitor.collect(statistics.addParameter(MonitorService.SUCCESS, 3).addParameter(MonitorService.CONCURRENT, 2).addParameter(MonitorService.INPUT, 1).addParameter(MonitorService.OUTPUT, 2));
    dubboMonitor.collect(statistics.addParameter(MonitorService.SUCCESS, 6).addParameter(MonitorService.ELAPSED, 2));
    dubboMonitor.send();
    ArgumentCaptor<URL> summaryCaptor = ArgumentCaptor.forClass(URL.class);
    verify(monitorService, atLeastOnce()).collect(summaryCaptor.capture());
    List<URL> allValues = summaryCaptor.getAllValues();
    assertThat(allValues, not(nullValue()));
    assertThat(allValues, hasItem(new CustomMatcher<URL>("Monitor count should greater than 1") {

        @Override
        public boolean matches(Object item) {
            URL url = (URL) item;
            return Integer.valueOf(url.getParameter(MonitorService.SUCCESS)) > 1;
        }
    }));
}
Also used : CustomMatcher(org.hamcrest.CustomMatcher) Invoker(org.apache.dubbo.rpc.Invoker) MonitorService(org.apache.dubbo.monitor.MonitorService) URL(org.apache.dubbo.common.URL) URLBuilder(org.apache.dubbo.common.URLBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with CustomMatcher

use of org.hamcrest.CustomMatcher in project kylo by Teradata.

the class DataSourceIT method testFindAll.

/**
 * Verifying retrieving all data sources.
 */
@Test
public void testFindAll() {
    // Create a feed data source
    final Connector[] connectors = listConnectors();
    Connector jdbcConnector = Arrays.asList(connectors).stream().filter(c -> c.getPluginId().equalsIgnoreCase("jdbc")).findFirst().orElse(null);
    DataSource ds = new DataSource();
    ds.setConnector(jdbcConnector);
    ds.setTitle("MySql Test");
    DefaultDataSetTemplate dsTemplate = new DefaultDataSetTemplate();
    Map<String, String> options = new HashMap<>();
    options.put("driver", "org.mariadb.jdbc.Driver");
    options.put("user", "root");
    options.put("password", "secret");
    options.put("url", "jdbc:mysql://localhost:3306/kylo");
    dsTemplate.setOptions(options);
    ds.setTemplate(dsTemplate);
    final DataSource jdbcDatasource = createDataSource(ds);
    // Find all data sources
    final SearchResult<DataSource> searchResult = given(DataSourceController.BASE).when().get().then().statusCode(200).extract().as(DataSourceSearchResult.class);
    final Matcher<DataSource> isHive = new CustomMatcher<DataSource>("is hive data source") {

        @Override
        public boolean matches(final Object item) {
            return (item instanceof DataSource && "Hive".equals(((DataSource) item).getTitle()));
        }
    };
    final Matcher<DataSource> isJdbc = new CustomMatcher<DataSource>("is jdbc data source") {

        @Override
        public boolean matches(final Object item) {
            final DataSource dataSource = (item instanceof DataSource) ? (DataSource) item : null;
            return (dataSource != null && jdbcDatasource.getId().equals(dataSource.getId()) && jdbcDatasource.getTitle().equals(dataSource.getTitle()));
        }
    };
    Assert.assertThat(searchResult.getData(), CoreMatchers.hasItem(isHive));
    Assert.assertThat(searchResult.getData(), CoreMatchers.hasItem(isJdbc));
    Assert.assertEquals(searchResult.getData().size(), searchResult.getRecordsTotal().longValue());
}
Also used : Connector(com.thinkbiganalytics.kylo.catalog.rest.model.Connector) CustomMatcher(org.hamcrest.CustomMatcher) HashMap(java.util.HashMap) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate) Test(org.junit.Test)

Example 3 with CustomMatcher

use of org.hamcrest.CustomMatcher in project jcabi-github by jcabi.

the class MkIssueTest method listsReadOnlyLabels.

/**
 * MkIssue can list its labels.
 * @throws Exception If some problem inside
 */
@Test
public void listsReadOnlyLabels() throws Exception {
    final Issue issue = this.issue();
    final String tag = "test-tag";
    issue.repo().labels().create(tag, "c0c0c0");
    issue.labels().add(Collections.singletonList(tag));
    MatcherAssert.assertThat(new Issue.Smart(issue).roLabels().iterate(), Matchers.<Label>hasItem(new CustomMatcher<Label>("label just created") {

        @Override
        public boolean matches(final Object item) {
            return Label.class.cast(item).name().equals(tag);
        }
    }));
}
Also used : Issue(com.jcabi.github.Issue) CustomMatcher(org.hamcrest.CustomMatcher) Test(org.junit.Test)

Example 4 with CustomMatcher

use of org.hamcrest.CustomMatcher in project kylo by Teradata.

the class DataSourceIT method testListFilesS3.

/**
 * Verify listing files from the Amazon S3 connector.
 */
@Test
public void testListFilesS3() {
    Assume.assumeNotNull(awsAccessKeyId, awsSecretAccessKey);
    // Create an S3 data source
    final Connector connector = new Connector();
    connector.setId("amazon-s3");
    final DefaultDataSetTemplate template = new DefaultDataSetTemplate();
    template.setOptions(new HashMap<>());
    template.getOptions().put("spark.hadoop.fs.s3a.access.key", awsAccessKeyId);
    template.getOptions().put("spark.hadoop.fs.s3a.secret.key", awsSecretAccessKey);
    final DataSource request = new DataSource();
    request.setConnector(connector);
    request.setTemplate(template);
    request.setTitle("test list files s3");
    final DataSource dataSource = given(DataSourceController.BASE).when().body(request).post().then().statusCode(200).extract().as(DataSource.class);
    // Test listing buckets
    final List<DataSetFile> buckets = given(DataSourceController.BASE).when().pathParam("id", dataSource.getId()).queryParam("path", "s3a:/").get("{id}/files").then().statusCode(200).extract().as(DataSetFileList.class);
    Assert.assertThat(buckets, CoreMatchers.hasItem(new CustomMatcher<DataSetFile>("DataSetFile name=thinkbig.greg directory=true") {

        @Override
        public boolean matches(final Object item) {
            return (item instanceof DataSetFile) && Objects.equals("thinkbig.greg", ((DataSetFile) item).getName()) && Objects.equals("s3a://thinkbig.greg/", ((DataSetFile) item).getPath()) && ((DataSetFile) item).isDirectory();
        }
    }));
    // Test listing files
    final List<DataSetFile> files = given(DataSourceController.BASE).when().pathParam("id", dataSource.getId()).queryParam("path", "s3a://thinkbig.greg/").get("{id}/files").then().statusCode(200).extract().as(DataSetFileList.class);
    Assert.assertThat(files, CoreMatchers.hasItem(new CustomMatcher<DataSetFile>("DataSetFile name=userdata1.csv directory=false") {

        @Override
        public boolean matches(Object item) {
            return (item instanceof DataSetFile) && Objects.equals("userdata1.csv", ((DataSetFile) item).getName()) && Objects.equals("s3a://thinkbig.greg/userdata1.csv", ((DataSetFile) item).getPath()) && !((DataSetFile) item).isDirectory();
        }
    }));
}
Also used : Connector(com.thinkbiganalytics.kylo.catalog.rest.model.Connector) CustomMatcher(org.hamcrest.CustomMatcher) DataSetFile(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile) DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Test(org.junit.Test)

Example 5 with CustomMatcher

use of org.hamcrest.CustomMatcher in project kylo by Teradata.

the class DataSourceIT method testListFilesAzureNative.

/**
 * Verify listing files from the Azure Storage connector.
 */
@Test
public void testListFilesAzureNative() {
    Assume.assumeNotNull(azureAccountKey);
    // Create an Azure data source
    final Connector connector = new Connector();
    connector.setId("azure-storage");
    final DefaultDataSetTemplate template = new DefaultDataSetTemplate();
    template.setOptions(Collections.singletonMap("spark.hadoop.fs.azure.account.key.kylogreg1.blob.core.windows.net", azureAccountKey));
    final DataSource request = new DataSource();
    request.setConnector(connector);
    request.setTemplate(template);
    request.setTitle("test list files wasb");
    final DataSource dataSource = given(DataSourceController.BASE).when().body(request).post().then().statusCode(200).extract().as(DataSource.class);
    // Test listing containers
    final List<DataSetFile> containers = given(DataSourceController.BASE).when().pathParam("id", dataSource.getId()).queryParam("path", "wasb://kylogreg1.blob.core.windows.net/").get("{id}/files").then().statusCode(200).extract().as(DataSetFileList.class);
    Assert.assertThat(containers, CoreMatchers.hasItem(new CustomMatcher<DataSetFile>("DataSetFile name=blob123 directory=true") {

        @Override
        public boolean matches(final Object item) {
            return (item instanceof DataSetFile) && Objects.equals("blob123", ((DataSetFile) item).getName()) && Objects.equals("wasb://blob123@kylogreg1.blob.core.windows.net/", ((DataSetFile) item).getPath()) && ((DataSetFile) item).isDirectory();
        }
    }));
    // Test listing files
    final List<DataSetFile> files = given(DataSourceController.BASE).when().pathParam("id", dataSource.getId()).queryParam("path", "wasb://blob123@kylogreg1.blob.core.windows.net/").get("{id}/files").then().statusCode(200).extract().as(DataSetFileList.class);
    Assert.assertThat(files, CoreMatchers.hasItem(new CustomMatcher<DataSetFile>("DataSetFile name=books1.json directory=true") {

        @Override
        public boolean matches(final Object item) {
            return (item instanceof DataSetFile) && Objects.equals("books1.json", ((DataSetFile) item).getName()) && Objects.equals("wasb://blob123@kylogreg1.blob.core.windows.net/books1.json", ((DataSetFile) item).getPath()) && !((DataSetFile) item).isDirectory();
        }
    }));
}
Also used : Connector(com.thinkbiganalytics.kylo.catalog.rest.model.Connector) CustomMatcher(org.hamcrest.CustomMatcher) DataSetFile(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile) DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Test(org.junit.Test)

Aggregations

CustomMatcher (org.hamcrest.CustomMatcher)5 Test (org.junit.Test)4 Connector (com.thinkbiganalytics.kylo.catalog.rest.model.Connector)3 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)3 DefaultDataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate)3 DataSetFile (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile)2 Issue (com.jcabi.github.Issue)1 HashMap (java.util.HashMap)1 URL (org.apache.dubbo.common.URL)1 URLBuilder (org.apache.dubbo.common.URLBuilder)1 MonitorService (org.apache.dubbo.monitor.MonitorService)1 Invoker (org.apache.dubbo.rpc.Invoker)1 Test (org.junit.jupiter.api.Test)1