Search in sources :

Example 1 with AttributeProxyDescriptor

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());
}
Also used : ProxySetupContext(cz.o2.proxima.transform.ElementWiseProxyTransform.ProxySetupContext) Test(org.junit.Test)

Example 2 with AttributeProxyDescriptor

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());
}
Also used : WriteProxy(cz.o2.proxima.transform.WriteProxy) Test(org.junit.Test)

Example 3 with AttributeProxyDescriptor

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());
}
Also used : Arrays(java.util.Arrays) TestTracker(cz.o2.proxima.storage.watermark.GlobalWatermarkThroughputLimiterTest.TestTracker) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) StorageType(cz.o2.proxima.storage.StorageType) DummyFilter(cz.o2.proxima.util.DummyFilter) EventDataToDummy(cz.o2.proxima.transform.EventDataToDummy) CachedView(cz.o2.proxima.direct.view.CachedView) StreamElement(cz.o2.proxima.storage.StreamElement) TransformationRunner(cz.o2.proxima.util.TransformationRunner) Map(java.util.Map) AttributeFamilyProxyDescriptor(cz.o2.proxima.repository.AttributeFamilyProxyDescriptor) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) TransformationDescriptor(cz.o2.proxima.repository.TransformationDescriptor) Optionals(cz.o2.proxima.util.Optionals) TestUtils(cz.o2.proxima.util.TestUtils) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) GlobalWatermarkThroughputLimiter(cz.o2.proxima.storage.watermark.GlobalWatermarkThroughputLimiter) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ConfigRepository(cz.o2.proxima.repository.ConfigRepository) KeyValue(cz.o2.proxima.direct.randomaccess.KeyValue) Assert.assertFalse(org.junit.Assert.assertFalse) Accept(cz.o2.proxima.storage.internal.AbstractDataAccessorFactory.Accept) Optional(java.util.Optional) ElementWiseTransformation(cz.o2.proxima.transform.ElementWiseTransformation) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ThroughputLimiter(cz.o2.proxima.storage.ThroughputLimiter) AttributeProxyDescriptor(cz.o2.proxima.repository.AttributeProxyDescriptor) Iterables(com.google.common.collect.Iterables) LimitedCommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReaders.LimitedCommitLogReader) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ConfigFactory(com.typesafe.config.ConfigFactory) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) RandomAccessReader(cz.o2.proxima.direct.randomaccess.RandomAccessReader) PassthroughFilter(cz.o2.proxima.storage.PassthroughFilter) Config(com.typesafe.config.Config) Assert.assertNotNull(org.junit.Assert.assertNotNull) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor) Assert.assertTrue(org.junit.Assert.assertTrue) CommitLogObserver(cz.o2.proxima.direct.commitlog.CommitLogObserver) IOException(java.io.IOException) Test(org.junit.Test) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) NotSerializableException(java.io.NotSerializableException) ReplicationRunner.runAttributeReplicas(cz.o2.proxima.util.ReplicationRunner.runAttributeReplicas) TimeUnit(java.util.concurrent.TimeUnit) GlobalWatermarkTracker(cz.o2.proxima.storage.watermark.GlobalWatermarkTracker) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) AttributeFamilyProxyDescriptor(cz.o2.proxima.repository.AttributeFamilyProxyDescriptor) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) Test(org.junit.Test)

Example 4 with AttributeProxyDescriptor

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;
}
Also used : ProxyTransform(cz.o2.proxima.transform.ProxyTransform)

Aggregations

Test (org.junit.Test)3 Iterables (com.google.common.collect.Iterables)1 Config (com.typesafe.config.Config)1 ConfigFactory (com.typesafe.config.ConfigFactory)1 CommitLogObserver (cz.o2.proxima.direct.commitlog.CommitLogObserver)1 CommitLogReader (cz.o2.proxima.direct.commitlog.CommitLogReader)1 LimitedCommitLogReader (cz.o2.proxima.direct.commitlog.CommitLogReaders.LimitedCommitLogReader)1 KeyValue (cz.o2.proxima.direct.randomaccess.KeyValue)1 RandomAccessReader (cz.o2.proxima.direct.randomaccess.RandomAccessReader)1 CachedView (cz.o2.proxima.direct.view.CachedView)1 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)1 AttributeFamilyDescriptor (cz.o2.proxima.repository.AttributeFamilyDescriptor)1 AttributeFamilyProxyDescriptor (cz.o2.proxima.repository.AttributeFamilyProxyDescriptor)1 AttributeProxyDescriptor (cz.o2.proxima.repository.AttributeProxyDescriptor)1 ConfigRepository (cz.o2.proxima.repository.ConfigRepository)1 EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)1 TransformationDescriptor (cz.o2.proxima.repository.TransformationDescriptor)1 PassthroughFilter (cz.o2.proxima.storage.PassthroughFilter)1 StorageType (cz.o2.proxima.storage.StorageType)1 StreamElement (cz.o2.proxima.storage.StreamElement)1