Search in sources :

Example 6 with ResourceClaimManager

use of org.apache.nifi.controller.repository.claim.ResourceClaimManager in project nifi by apache.

the class TestFileSystemSwapManager method createSwapManager.

private FileSystemSwapManager createSwapManager() {
    final FileSystemSwapManager swapManager = new FileSystemSwapManager();
    final ResourceClaimManager resourceClaimManager = new NopResourceClaimManager();
    final FlowFileRepository flowfileRepo = Mockito.mock(FlowFileRepository.class);
    swapManager.initialize(new SwapManagerInitializationContext() {

        @Override
        public ResourceClaimManager getResourceClaimManager() {
            return resourceClaimManager;
        }

        @Override
        public FlowFileRepository getFlowFileRepository() {
            return flowfileRepo;
        }

        @Override
        public EventReporter getEventReporter() {
            return EventReporter.NO_OP;
        }
    });
    return swapManager;
}
Also used : FlowFileRepository(org.apache.nifi.controller.repository.FlowFileRepository) ResourceClaimManager(org.apache.nifi.controller.repository.claim.ResourceClaimManager) SwapManagerInitializationContext(org.apache.nifi.controller.repository.SwapManagerInitializationContext) EventReporter(org.apache.nifi.events.EventReporter)

Example 7 with ResourceClaimManager

use of org.apache.nifi.controller.repository.claim.ResourceClaimManager in project nifi by apache.

the class TestSchemaSwapSerializerDeserializer method testRoundTripSerializeDeserializeSummary.

@Test
public void testRoundTripSerializeDeserializeSummary() throws IOException {
    final ResourceClaimManager resourceClaimManager = new StandardResourceClaimManager();
    final ResourceClaim firstResourceClaim = resourceClaimManager.newResourceClaim("container", "section", "id", true, false);
    resourceClaimManager.incrementClaimantCount(firstResourceClaim);
    final List<FlowFileRecord> toSwap = new ArrayList<>(10000);
    final Map<String, String> attrs = new HashMap<>();
    long size = 0L;
    final ContentClaim firstClaim = MockFlowFile.createContentClaim("id", resourceClaimManager);
    for (int i = 0; i < 10000; i++) {
        attrs.put("i", String.valueOf(i));
        final FlowFileRecord ff = i < 2 ? new MockFlowFile(attrs, i, firstClaim) : new MockFlowFile(attrs, i, resourceClaimManager);
        toSwap.add(ff);
        size += i;
    }
    final FlowFileQueue flowFileQueue = Mockito.mock(FlowFileQueue.class);
    Mockito.when(flowFileQueue.getIdentifier()).thenReturn("87bb99fe-412c-49f6-a441-d1b0af4e20b4");
    final String swapLocation = "target/testRoundTrip.swap";
    final File swapFile = new File(swapLocation);
    Files.deleteIfExists(swapFile.toPath());
    final SwapSerializer serializer = new SchemaSwapSerializer();
    try (final FileOutputStream fos = new FileOutputStream(swapFile)) {
        serializer.serializeFlowFiles(toSwap, flowFileQueue, swapLocation, fos);
    }
    final SwapDeserializer deserializer = new SchemaSwapDeserializer();
    final SwapSummary swapSummary;
    try (final FileInputStream fis = new FileInputStream(swapFile);
        final DataInputStream dis = new DataInputStream(fis)) {
        swapSummary = deserializer.getSwapSummary(dis, swapLocation, resourceClaimManager);
    }
    assertEquals(10000, swapSummary.getQueueSize().getObjectCount());
    assertEquals(size, swapSummary.getQueueSize().getByteCount());
    assertEquals(9999, swapSummary.getMaxFlowFileId().intValue());
    final List<ResourceClaim> resourceClaims = swapSummary.getResourceClaims();
    assertEquals(10000, resourceClaims.size());
    assertFalse(resourceClaims.stream().anyMatch(claim -> claim == null));
    assertEquals(2, resourceClaims.stream().filter(claim -> claim.getId().equals("id")).collect(Collectors.counting()).intValue());
    final Set<ResourceClaim> uniqueClaims = new HashSet<>(resourceClaims);
    assertEquals(9999, uniqueClaims.size());
}
Also used : ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) SwapContents(org.apache.nifi.controller.repository.SwapContents) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) HashMap(java.util.HashMap) BufferedOutputStream(java.io.BufferedOutputStream) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) Map(java.util.Map) Before(org.junit.Before) OutputStream(java.io.OutputStream) NullOutputStream(org.apache.nifi.stream.io.NullOutputStream) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) SwapSummary(org.apache.nifi.controller.repository.SwapSummary) ResourceClaimManager(org.apache.nifi.controller.repository.claim.ResourceClaimManager) Mockito(org.mockito.Mockito) List(java.util.List) Ignore(org.junit.Ignore) Assert.assertFalse(org.junit.Assert.assertFalse) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) ResourceClaimManager(org.apache.nifi.controller.repository.claim.ResourceClaimManager) SwapSummary(org.apache.nifi.controller.repository.SwapSummary) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) HashSet(java.util.HashSet) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) FileOutputStream(java.io.FileOutputStream) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) File(java.io.File) Test(org.junit.Test)

Example 8 with ResourceClaimManager

use of org.apache.nifi.controller.repository.claim.ResourceClaimManager in project nifi by apache.

the class TestSimpleSwapSerializerDeserializer method testWritePerformance.

@Test
@Ignore("For manual testing only. Not intended to be run as part of the automated unit tests but can " + "be convenient for determining a baseline for performance if making modifications.")
public void testWritePerformance() throws IOException, InterruptedException {
    final ResourceClaimManager resourceClaimManager = new StandardResourceClaimManager();
    final List<FlowFileRecord> toSwap = new ArrayList<>(10000);
    final Map<String, String> attrs = new HashMap<>();
    for (int i = 0; i < 10000; i++) {
        attrs.put("i", String.valueOf(i));
        final FlowFileRecord ff = new MockFlowFile(attrs, i, resourceClaimManager);
        toSwap.add(ff);
    }
    final FlowFileQueue flowFileQueue = Mockito.mock(FlowFileQueue.class);
    Mockito.when(flowFileQueue.getIdentifier()).thenReturn("87bb99fe-412c-49f6-a441-d1b0af4e20b4");
    final String swapLocation = "target/testRoundTrip.swap";
    final int iterations = 1000;
    final long start = System.nanoTime();
    final SwapSerializer serializer = new SimpleSwapSerializer();
    for (int i = 0; i < iterations; i++) {
        try (final OutputStream out = new NullOutputStream()) {
            serializer.serializeFlowFiles(toSwap, flowFileQueue, swapLocation, out);
        }
    }
    final long millis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
    System.out.println("Wrote " + iterations + " Swap Files in " + millis + " millis");
}
Also used : HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) NullOutputStream(org.apache.nifi.stream.io.NullOutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) ResourceClaimManager(org.apache.nifi.controller.repository.claim.ResourceClaimManager) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) NullOutputStream(org.apache.nifi.stream.io.NullOutputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ResourceClaimManager (org.apache.nifi.controller.repository.claim.ResourceClaimManager)8 ArrayList (java.util.ArrayList)7 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)7 StandardResourceClaimManager (org.apache.nifi.controller.repository.claim.StandardResourceClaimManager)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)6 FileOutputStream (java.io.FileOutputStream)5 FlowFileRecord (org.apache.nifi.controller.repository.FlowFileRecord)5 OutputStream (java.io.OutputStream)4 NullOutputStream (org.apache.nifi.stream.io.NullOutputStream)4 Ignore (org.junit.Ignore)4 BufferedOutputStream (java.io.BufferedOutputStream)3 DataInputStream (java.io.DataInputStream)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 SwapContents (org.apache.nifi.controller.repository.SwapContents)3 BufferedInputStream (java.io.BufferedInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 List (java.util.List)2