use of cz.o2.proxima.repository.AttributeProxyDescriptor in project proxima-platform by O2-Czech-Republic.
the class ConfigRepositoryTest method testProxySetupContext.
@Test
public void testProxySetupContext() {
EntityDescriptor entity = repo.getEntity("proxied");
AttributeDescriptor<Object> attribute = entity.getAttribute("raw.*");
AttributeProxyDescriptor<Object> proxy = entity.getAttribute("event.*").asProxy();
ProxySetupContext context = ConfigRepository.asProxySetupContext(proxy, attribute, true, false);
assertTrue(context.isReadTransform());
assertFalse(context.isWriteTransform());
assertFalse(context.isSymmetric());
assertEquals(attribute, context.getTargetAttribute());
assertEquals(proxy, context.getProxyAttribute());
}
use of cz.o2.proxima.repository.AttributeProxyDescriptor in project proxima-platform by O2-Czech-Republic.
the class ConfigRepositoryTest method testProxySetuped.
@Test
public void testProxySetuped() {
AttributeProxyDescriptor<Object> proxy = repo.getEntity("proxied").getAttribute("asymmetric..*").asProxy();
WriteProxy transform = (WriteProxy) proxy.getWriteTransform();
assertEquals("_e.", Objects.requireNonNull(transform).getTarget());
}
use of cz.o2.proxima.repository.AttributeProxyDescriptor in project proxima-platform by O2-Czech-Republic.
the class DirectDataOperatorTest method testReplicationProxies.
@Test
public void testReplicationProxies() {
repo.reloadConfig(true, ConfigFactory.load("test-replication-proxy.conf").resolve());
EntityDescriptor dummy = repo.getEntity("dummy");
// attribute _d should be proxy to
// _dummyReplicationMasterSlave_write$_d
// and _dummyReplicationMasterSlave_replicated$_d
AttributeDescriptor<Object> _d = dummy.getAttribute("_d", true);
assertTrue(_d.isProxy());
Set<AttributeFamilyDescriptor> families = repo.getFamiliesForAttribute(_d);
assertEquals(1, families.size());
AttributeFamilyDescriptor primary = Iterables.getOnlyElement(families);
assertTrue("Family " + primary + " must be proxy", primary.isProxy());
AttributeFamilyProxyDescriptor proxy = (AttributeFamilyProxyDescriptor) primary;
assertEquals("proxy::replication_dummy-replication-proxied-slave_replicated::" + "replication_dummy-replication-proxied-slave_write", primary.getName());
assertEquals("replication_dummy-replication-proxied-slave_replicated", proxy.getTargetFamilyRead().getName());
assertEquals("replication_dummy-replication-proxied-slave_write", proxy.getTargetFamilyWrite().getName());
assertFalse(proxy.getTargetFamilyRead().isProxy());
assertFalse(proxy.getTargetFamilyWrite().isProxy());
assertEquals(1, proxy.getAttributes().size());
AttributeProxyDescriptor<?> attr;
attr = (AttributeProxyDescriptor<?>) _d;
assertNotNull(attr.getWriteTransform());
assertEquals("_d", attr.getWriteTransform().asElementWise().fromProxy("_d"));
assertEquals("_d", attr.getWriteTransform().asElementWise().toProxy("_d"));
assertNotNull(attr.getReadTransform());
assertEquals("_d", attr.getReadTransform().asElementWise().fromProxy("_d"));
assertEquals("_d", attr.getReadTransform().asElementWise().toProxy("_d"));
// attribute dummy.data should be proxy to _d
attr = (AttributeProxyDescriptor<?>) dummy.getAttribute("data");
assertNotNull(attr.getWriteTransform());
assertNotNull(attr.getReadTransform());
assertEquals("data", attr.getWriteTransform().asElementWise().toProxy("_d"));
assertEquals("data", attr.getReadTransform().asElementWise().toProxy("_d"));
assertEquals("_d", attr.getWriteTransform().asElementWise().fromProxy("data"));
assertEquals("_d", attr.getReadTransform().asElementWise().fromProxy("data"));
families = repo.getFamiliesForAttribute(attr);
assertEquals(2, families.size());
primary = families.stream().filter(af -> af.getType() == StorageType.PRIMARY).findAny().orElse(null);
assertNotNull(primary);
assertTrue(primary.isProxy());
proxy = (AttributeFamilyProxyDescriptor) primary;
assertEquals("proxy::proxy::replication_dummy-replication-proxied-slave_replicated" + "::replication_dummy-replication-proxied-slave_write::proxy" + "::replication_dummy-replication-proxied-slave_replicated" + "::replication_dummy-replication-proxied-slave_write", primary.getName());
assertEquals("proxy::replication_dummy-replication-proxied-slave_replicated::" + "replication_dummy-replication-proxied-slave_write", proxy.getTargetFamilyRead().getName());
assertEquals("proxy::replication_dummy-replication-proxied-slave_replicated::" + "replication_dummy-replication-proxied-slave_write", proxy.getTargetFamilyWrite().getName());
assertTrue(proxy.getTargetFamilyRead().isProxy());
assertTrue(proxy.getTargetFamilyWrite().isProxy());
assertEquals(1, proxy.getAttributes().size());
}
use of cz.o2.proxima.repository.AttributeProxyDescriptor in project proxima-platform by O2-Czech-Republic.
the class AttributeFamilyProxyDataAccessor method transformSingleRead.
private StreamElement transformSingleRead(StreamElement input) {
AttributeProxyDescriptor<?> attr = lookupTarget.get(input.getAttributeDescriptor());
if (attr != null) {
ProxyTransform transform = attr.getReadTransform();
String attribute = transform.asElementWise().toProxy(input.getAttribute());
return StreamElement.upsert(input.getEntityDescriptor(), attr, input.getUuid(), input.getKey(), attribute, input.getStamp(), input.getValue());
}
log.warn("Received unknown attribute {}. Letting though, but this " + "might cause other issues.", input.getAttributeDescriptor());
return input;
}
Aggregations