Search in sources :

Example 1 with QueryMetric

use of datawave.microservice.querymetric.QueryMetric in project datawave by NationalSecurityAgency.

the class QueryExecutorBeanTest method testPredict.

@SuppressWarnings("unchecked")
@Test
public void testPredict() throws Exception {
    QueryImpl q = createNewQuery();
    MultivaluedMap p = createNewQueryParameterMap();
    p.putSingle(QueryParameters.QUERY_LOGIC_NAME, queryLogicName);
    MultivaluedMap<String, String> optionalParameters = createNewQueryParameters(q, p);
    @SuppressWarnings("rawtypes") QueryLogic logic = createMock(BaseQueryLogic.class);
    DatawaveUser user = new DatawaveUser(SubjectIssuerDNPair.of(userDN, "<CN=MY_CA, OU=MY_SUBDIVISION, OU=MY_DIVISION, O=ORG, C=US>"), UserType.USER, Arrays.asList(auths), null, null, 0L);
    DatawavePrincipal principal = new DatawavePrincipal(Collections.singletonList(user));
    String[] dns = principal.getDNs();
    Arrays.sort(dns);
    List<String> dnList = Arrays.asList(dns);
    PowerMock.resetAll();
    EasyMock.expect(ctx.getCallerPrincipal()).andReturn(principal).anyTimes();
    suppress(constructor(QueryParametersImpl.class));
    EasyMock.expect(persister.create(principal.getUserDN().subjectDN(), dnList, (SecurityMarking) Whitebox.getField(bean.getClass(), "marking").get(bean), queryLogicName, (QueryParameters) Whitebox.getField(bean.getClass(), "qp").get(bean), optionalParameters)).andReturn(q);
    EasyMock.expect(queryLogicFactory.getQueryLogic(queryLogicName, principal)).andReturn(logic);
    EasyMock.expect(logic.getRequiredQueryParameters()).andReturn(Collections.EMPTY_SET);
    EasyMock.expect(logic.containsDNWithAccess(dnList)).andReturn(true);
    EasyMock.expect(logic.getMaxPageSize()).andReturn(0);
    BaseQueryMetric metric = new QueryMetricFactoryImpl().createMetric();
    metric.populate(q);
    metric.setQueryType(RunningQuery.class.getSimpleName());
    QueryMetric testMetric = new QueryMetric((QueryMetric) metric) {

        @Override
        public boolean equals(Object o) {
            // test for equality except for the create date
            if (null == o) {
                return false;
            }
            if (this == o) {
                return true;
            }
            if (o instanceof QueryMetric) {
                QueryMetric other = (QueryMetric) o;
                return new EqualsBuilder().append(this.getQueryId(), other.getQueryId()).append(this.getQueryType(), other.getQueryType()).append(this.getQueryAuthorizations(), other.getQueryAuthorizations()).append(this.getColumnVisibility(), other.getColumnVisibility()).append(this.getBeginDate(), other.getBeginDate()).append(this.getEndDate(), other.getEndDate()).append(this.getCreateDate(), other.getCreateDate()).append(this.getSetupTime(), other.getSetupTime()).append(this.getUser(), other.getUser()).append(this.getUserDN(), other.getUserDN()).append(this.getQuery(), other.getQuery()).append(this.getQueryLogic(), other.getQueryLogic()).append(this.getQueryName(), other.getQueryName()).append(this.getParameters(), other.getParameters()).append(this.getHost(), other.getHost()).append(this.getPageTimes(), other.getPageTimes()).append(this.getProxyServers(), other.getProxyServers()).append(this.getLifecycle(), other.getLifecycle()).append(this.getErrorMessage(), other.getErrorMessage()).append(this.getErrorCode(), other.getErrorCode()).append(this.getSourceCount(), other.getSourceCount()).append(this.getNextCount(), other.getNextCount()).append(this.getSeekCount(), other.getSeekCount()).append(this.getYieldCount(), other.getYieldCount()).append(this.getDocRanges(), other.getDocRanges()).append(this.getFiRanges(), other.getFiRanges()).append(this.getPlan(), other.getPlan()).append(this.getVersion(), other.getVersion()).append(this.getLoginTime(), other.getLoginTime()).append(this.getPredictions(), other.getPredictions()).isEquals();
            } else {
                return false;
            }
        }
    };
    Set<Prediction> predictions = new HashSet<>();
    predictions.add(new Prediction("source", 1));
    EasyMock.expect(predictor.predict(EasyMock.eq(testMetric))).andReturn(predictions);
    PowerMock.replayAll();
    GenericResponse<String> response = bean.predictQuery(queryLogicName, p);
    PowerMock.verifyAll();
    Object cachedRunningQuery = cache.get(q.getId().toString());
    Assert.assertNull(cachedRunningQuery);
    Assert.assertEquals(predictions.toString(), response.getResult());
}
Also used : DatawaveUser(datawave.security.authorization.DatawaveUser) Prediction(datawave.microservice.querymetric.BaseQueryMetric.Prediction) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) QueryLogic(datawave.webservice.query.logic.QueryLogic) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) QueryImpl(datawave.webservice.query.QueryImpl) BaseQueryMetric(datawave.microservice.querymetric.BaseQueryMetric) QueryMetric(datawave.microservice.querymetric.QueryMetric) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BaseQueryMetric(datawave.microservice.querymetric.BaseQueryMetric) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with QueryMetric

use of datawave.microservice.querymetric.QueryMetric in project datawave by NationalSecurityAgency.

the class QueryMetricUtilTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    Mutation m = QueryMetricUtil.toMutation(metric);
    QueryMetric metric2 = (QueryMetric) QueryMetricUtil.toMetric(new Value(m.getUpdates().get(0).getValue()));
    Assert.assertEquals(metric, metric2);
}
Also used : QueryMetric(datawave.microservice.querymetric.QueryMetric) Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 3 with QueryMetric

use of datawave.microservice.querymetric.QueryMetric in project datawave by NationalSecurityAgency.

the class QueryMetricUtilTest method setup.

@Before
public void setup() {
    metric = new QueryMetric();
    metric.setQueryId(queryId);
    metric.setQueryType(queryType);
    metric.setSetupTime(setupTime);
    metric.setUser(sid);
    metric.getPageTimes().add(page1);
    metric.getPageTimes().add(page2);
}
Also used : QueryMetric(datawave.microservice.querymetric.QueryMetric) Before(org.junit.Before)

Example 4 with QueryMetric

use of datawave.microservice.querymetric.QueryMetric in project datawave by NationalSecurityAgency.

the class QueryMetricUtil method toMetric.

public static BaseQueryMetric toMetric(Value value) throws IOException, ClassNotFoundException {
    byte[] b = value.get();
    QueryMetric m = new QueryMetric();
    ProtobufIOUtil.mergeFrom(b, m, m.cachedSchema());
    return m;
}
Also used : BaseQueryMetric(datawave.microservice.querymetric.BaseQueryMetric) QueryMetric(datawave.microservice.querymetric.QueryMetric)

Example 5 with QueryMetric

use of datawave.microservice.querymetric.QueryMetric in project datawave by NationalSecurityAgency.

the class QueryPlanTest method before.

@Before
public void before() {
    // Use RunningQuery to test that query metrics being updated with plan
    this.useRunningQuery();
    // Provide a QueryMetric to test harness to verify it's updated
    metric = new QueryMetric();
    this.withMetric(metric);
}
Also used : QueryMetric(datawave.microservice.querymetric.QueryMetric) Before(org.junit.Before)

Aggregations

QueryMetric (datawave.microservice.querymetric.QueryMetric)7 Test (org.junit.Test)3 BaseQueryMetric (datawave.microservice.querymetric.BaseQueryMetric)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 Prediction (datawave.microservice.querymetric.BaseQueryMetric.Prediction)1 QueryMetricFactoryImpl (datawave.microservice.querymetric.QueryMetricFactoryImpl)1 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)1 DatawaveUser (datawave.security.authorization.DatawaveUser)1 QueryImpl (datawave.webservice.query.QueryImpl)1 QueryParametersImpl (datawave.webservice.query.QueryParametersImpl)1 BaseQueryLogic (datawave.webservice.query.logic.BaseQueryLogic)1 QueryLogic (datawave.webservice.query.logic.QueryLogic)1 QueryGeometry (datawave.webservice.query.map.QueryGeometry)1 QueryGeometryResponse (datawave.webservice.query.map.QueryGeometryResponse)1 HashSet (java.util.HashSet)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 Mutation (org.apache.accumulo.core.data.Mutation)1 Value (org.apache.accumulo.core.data.Value)1 EqualsBuilder (org.apache.commons.lang.builder.EqualsBuilder)1