Search in sources :

Example 31 with DataPointService

use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by MangoAutomation.

the class DataPointTagsDaoTest method updateTags.

// @Test
public void updateTags() {
    System.out.println(Common.MA_DATA_PATH);
    LongSummaryStatistics stats;
    DataPointService dataPointService = Common.getBean(DataPointService.class);
    MockDataSourceVO ds = createMockDataSource(true);
    List<DataPointVO> points = Stream.generate(() -> createMockDataPoint(ds, new MockPointLocatorVO(DataType.NUMERIC, true), true)).limit(numPoints).collect(Collectors.toList());
    AtomicInteger count = new AtomicInteger();
    List<String> tagKeys = Stream.generate(() -> "key" + count.getAndIncrement()).limit(numTags).collect(Collectors.toList());
    // add half the tags
    stats = points.stream().mapToLong(point -> {
        point.setTags(tagKeys.stream().limit(numTags / 2).collect(Collectors.toMap(Function.identity(), k -> k + "_value" + random.nextInt(10))));
        long start = System.currentTimeMillis();
        dataPointService.update(point.getId(), point);
        return System.currentTimeMillis() - start;
    }).summaryStatistics();
    System.out.println("add half the tags: " + stats);
    // add/update the tags
    stats = points.stream().mapToLong(point -> {
        point.setTags(tagKeys.stream().collect(Collectors.toMap(Function.identity(), k -> k + "_value" + random.nextInt(10))));
        long start = System.currentTimeMillis();
        dataPointService.update(point.getId(), point);
        return System.currentTimeMillis() - start;
    }).summaryStatistics();
    System.out.println("add/update the tags: " + stats);
    // save without updating tags
    stats = points.stream().mapToLong(point -> {
        long start = System.currentTimeMillis();
        dataPointService.update(point.getId(), point);
        return System.currentTimeMillis() - start;
    }).summaryStatistics();
    System.out.println("save without updating tags: " + stats);
    // remove half of the tags
    stats = points.stream().mapToLong(point -> {
        Map<String, String> existing = point.getTags();
        point.setTags(tagKeys.stream().limit(numTags / 2).collect(Collectors.toMap(Function.identity(), existing::get)));
        long start = System.currentTimeMillis();
        dataPointService.update(point.getId(), point);
        return System.currentTimeMillis() - start;
    }).summaryStatistics();
    System.out.println("remove half of the tags: " + stats);
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)

Example 32 with DataPointService

use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by MangoAutomation.

the class DataSourceDaoDeadlockDetection method detectDeadlockFromDataSourceDeleteDataPointInsertAndDelete.

/**
 * See the deadlock when you insert data source, then point,
 *  then delete point (outside of transaction) then delete source
 */
@Test
public void detectDeadlockFromDataSourceDeleteDataPointInsertAndDelete() {
    // Create data source
    // Add data point
    // Delete data source
    // Create data source
    // 25;
    int numThreads = 5;
    // 100;
    int numDataSources = 10;
    PermissionService permissionService = Common.getBean(PermissionService.class);
    DataSourceService dataSourceService = Common.getBean(DataSourceService.class);
    DataPointService dataPointService = Common.getBean(DataPointService.class);
    AtomicInteger successes = new AtomicInteger();
    AtomicInteger failures = new AtomicInteger();
    AtomicInteger running = new AtomicInteger(numThreads);
    MutableObject<Exception> failure = new MutableObject<>(null);
    for (int i = 0; i < numThreads; i++) {
        new Thread() {

            @Override
            public void run() {
                try {
                    for (int i = 0; i < numDataSources; i++) {
                        // Create data source
                        MockDataSourceVO ds = new MockDataSourceVO();
                        ds.setName(Common.generateXid("Mock "));
                        dataSourceService.insert(ds);
                        // Create and save point
                        DataPointVO dp = createMockDataPoint(ds, new MockPointLocatorVO());
                        // Delete point
                        dataPointService.delete(dp.getId());
                        // Delete data source
                        dataSourceService.delete(ds.getId());
                        successes.getAndIncrement();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    failure.setValue(e);
                    failures.getAndIncrement();
                } finally {
                    running.decrementAndGet();
                }
            }
        }.start();
    }
    while (running.get() > 0) {
        try {
            Thread.sleep(100);
        } catch (Exception e) {
        }
    }
    if (failures.get() > 0) {
        fail("Ran " + successes.get() + " queries: " + failure.getValue().getMessage());
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) DataSourceService(com.infiniteautomation.mango.spring.service.DataSourceService) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MutableObject(org.apache.commons.lang3.mutable.MutableObject) Test(org.junit.Test)

Example 33 with DataPointService

use of com.infiniteautomation.mango.spring.service.DataPointService in project ma-core-public by MangoAutomation.

the class NumericPointValueWithDifferentSeriesIdTest method createMockDataPoints.

@Override
protected List<IDataPoint> createMockDataPoints(int count) {
    List<IDataPoint> points = super.createMockDataPoints(count);
    // Change series id
    DataPointService service = Common.getBean(DataPointService.class);
    DataPointDao dao = Common.getBean(DataPointDao.class);
    for (IDataPoint point : points) {
        DataPointVO vo = (DataPointVO) point;
        vo.setSeriesId(dao.insertNewTimeSeries());
        try {
            service.update(vo.getId(), vo);
        } catch (ValidationException e) {
            String failureMessage = "";
            for (ProcessMessage m : e.getValidationResult().getMessages()) {
                String messagePart = m.getContextKey() + " -> " + m.getContextualMessage().translate(Common.getTranslations()) + "\n";
                failureMessage += messagePart;
            }
            fail(failureMessage);
        }
    }
    return points;
}
Also used : DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage)

Aggregations

DataPointService (com.infiniteautomation.mango.spring.service.DataPointService)33 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)31 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)20 List (java.util.List)20 Common (com.serotonin.m2m2.Common)19 Collectors (java.util.stream.Collectors)19 MangoTestBase (com.serotonin.m2m2.MangoTestBase)18 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)18 Test (org.junit.Test)18 Role (com.serotonin.m2m2.vo.role.Role)17 Set (java.util.Set)17 RunAs (com.infiniteautomation.mango.spring.components.RunAs)16 QueryBuilder (com.serotonin.m2m2.db.dao.QueryBuilder)16 Assert.assertEquals (org.junit.Assert.assertEquals)16 Assert.assertTrue (org.junit.Assert.assertTrue)16 Before (org.junit.Before)16 RoleDao (com.serotonin.m2m2.db.dao.RoleDao)12 MockPointLocatorVO (com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)10 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)6 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)6