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);
}
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());
}
}
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;
}
Aggregations