test_class.file: proxy/src/test/java/com/wavefront/agent/queueing/QueueExporterTest.java
test_class.identifier: QueueExporterTest
test_case.body: @Test
    public void testQueueExporter() throws Exception {
      File file = new File(File.createTempFile("proxyTestConverter", null).getPath() + ".queue");
      file.deleteOnExit();
      ProxyConfig config = new ProxyConfig();
      config.parseArguments(new String[]{
          "--flushThreads", "2",
          "--buffer", file.getAbsolutePath(),
          "--exportQueuePorts", "2878",
          "--exportQueueOutputFile", file.getAbsolutePath() + "-output",
          "--exportQueueRetainData", "false"
      }, "proxy");
      TaskQueueFactory taskQueueFactory = new TaskQueueFactoryImpl(config.getBufferFile(), false);
      EntityPropertiesFactory entityPropertiesFactory = new EntityPropertiesFactoryImpl(config);
      QueueExporter qe = new QueueExporter(config, taskQueueFactory, entityPropertiesFactory);
      BufferedWriter mockedWriter = EasyMock.createMock(BufferedWriter.class);
      reset(mockedWriter);
      HandlerKey key = HandlerKey.of(ReportableEntityType.POINT, "2878");
      TaskQueue<LineDelimitedDataSubmissionTask> queue = taskQueueFactory.getTaskQueue(key, 0);
      queue.clear();
      UUID proxyId = UUID.randomUUID();
      LineDelimitedDataSubmissionTask task = new LineDelimitedDataSubmissionTask(null, proxyId,
          new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT,
          "2878", ImmutableList.of("item1", "item2", "item3"), () -> 12345L);
      task.enqueue(QueueingReason.RETRY);
      LineDelimitedDataSubmissionTask task2 = new LineDelimitedDataSubmissionTask(null, proxyId,
          new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT,
          "2878", ImmutableList.of("item4", "item5"), () -> 12345L);
      task2.enqueue(QueueingReason.RETRY);
      mockedWriter.write("item1");
      mockedWriter.newLine();
      mockedWriter.write("item2");
      mockedWriter.newLine();
      mockedWriter.write("item3");
      mockedWriter.newLine();
      mockedWriter.write("item4");
      mockedWriter.newLine();
      mockedWriter.write("item5");
      mockedWriter.newLine();
  
      TaskQueue<EventDataSubmissionTask> queue2 = taskQueueFactory.
          getTaskQueue(HandlerKey.of(ReportableEntityType.EVENT, "2888"), 0);
      queue2.clear();
      EventDataSubmissionTask eventTask = new EventDataSubmissionTask(null, proxyId,
          new DefaultEntityPropertiesForTesting(), queue2, "2888",
          ImmutableList.of(
              new Event(ReportEvent.newBuilder().
                  setStartTime(123456789L * 1000).
                  setEndTime(123456789L * 1000 + 1).
                  setName("Event name for testing").
                  setHosts(ImmutableList.of("host1", "host2")).
                  setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).
                  setAnnotations(ImmutableMap.of("severity", "INFO")).
                  setTags(ImmutableList.of("tag1")).
                  build()),
              new Event(ReportEvent.newBuilder().
                  setStartTime(123456789L * 1000).
                  setEndTime(123456789L * 1000 + 1).
                  setName("Event name for testing").
                  setHosts(ImmutableList.of("host1", "host2")).
                  setAnnotations(ImmutableMap.of("severity", "INFO")).
                  build()
              )),
          () -> 12345L);
      eventTask.enqueue(QueueingReason.RETRY);
      mockedWriter.write("@Event 123456789000 123456789001 \"Event name for testing\" " +
          "\"host\"=\"host1\" \"host\"=\"host2\" \"severity\"=\"INFO\" \"multi\"=\"bar\" " +
          "\"multi\"=\"baz\" \"tag\"=\"tag1\"");
      mockedWriter.newLine();
      mockedWriter.write("@Event 123456789000 123456789001 \"Event name for testing\" " +
          "\"host\"=\"host1\" \"host\"=\"host2\" \"severity\"=\"INFO\"");
      mockedWriter.newLine();
  
      TaskQueue<SourceTagSubmissionTask> queue3 = taskQueueFactory.
          getTaskQueue(HandlerKey.of(ReportableEntityType.SOURCE_TAG, "2898"), 0);
      queue3.clear();
      SourceTagSubmissionTask sourceTagTask = new SourceTagSubmissionTask(null,
          new DefaultEntityPropertiesForTesting(), queue3, "2898",
          new SourceTag(
              ReportSourceTag.newBuilder().setOperation(SourceOperationType.SOURCE_TAG).
                  setAction(SourceTagAction.SAVE).setSource("testSource").
                  setAnnotations(ImmutableList.of("newtag1", "newtag2")).build()),
          () -> 12345L);
      sourceTagTask.enqueue(QueueingReason.RETRY);
      mockedWriter.write("@SourceTag action=save source=\"testSource\" \"newtag1\" \"newtag2\"");
      mockedWriter.newLine();
  
      expectLastCall().once();
      replay(mockedWriter);
  
      assertEquals(2, queue.size());
      qe.processQueue(queue, mockedWriter);
      assertEquals(0, queue.size());
  
      assertEquals(1, queue2.size());
      qe.processQueue(queue2, mockedWriter);
      assertEquals(0, queue2.size());
  
      assertEquals(1, queue3.size());
      qe.processQueue(queue3, mockedWriter);
      assertEquals(0, queue3.size());
  
      verify(mockedWriter);
  
      List<String> files = QueueExporter.listFiles(file.getAbsolutePath()).stream().
          map(x -> x.replace(file.getAbsolutePath() + ".", "")).collect(Collectors.toList());
      assertEquals(3, files.size());
      assertTrue(files.contains("points.2878.0.spool"));
      assertTrue(files.contains("events.2888.0.spool"));
      assertTrue(files.contains("sourceTags.2898.0.spool"));
  
      HandlerKey k1 = HandlerKey.of(ReportableEntityType.POINT, "2878");
      HandlerKey k2 = HandlerKey.of(ReportableEntityType.EVENT, "2888");
      HandlerKey k3 = HandlerKey.of(ReportableEntityType.SOURCE_TAG, "2898");
      files = QueueExporter.listFiles(file.getAbsolutePath());
      Set<HandlerKey> hk = QueueExporter.getValidHandlerKeys(files, "all");
      assertEquals(3, hk.size());
      assertTrue(hk.contains(k1));
      assertTrue(hk.contains(k2));
      assertTrue(hk.contains(k3));
  
      hk = QueueExporter.getValidHandlerKeys(files, "2878, 2898");
      assertEquals(2, hk.size());
      assertTrue(hk.contains(k1));
      assertTrue(hk.contains(k3));
  
      hk = QueueExporter.getValidHandlerKeys(files, "2888");
      assertEquals(1, hk.size());
      assertTrue(hk.contains(k2));
    }
test_case.class_method_signature: QueueExporterTest.testQueueExporter()
test_case.full_signature: @Test public void testQueueExporter()
test_case.identifier: testQueueExporter
test_case.invocations: getPath createTempFile deleteOnExit parseArguments getAbsolutePath getAbsolutePath getBufferFile createMock reset of getTaskQueue clear randomUUID of enqueue of enqueue write newLine write newLine write newLine write newLine write newLine getTaskQueue of clear of build setTags setAnnotations setDimensions setHosts setName setEndTime setStartTime newBuilder of of of of of build setAnnotations setHosts setName setEndTime setStartTime newBuilder of of enqueue write newLine write newLine getTaskQueue of clear build setAnnotations setSource setAction setOperation newBuilder of enqueue write newLine once expectLastCall replay assertEquals size processQueue assertEquals size assertEquals size processQueue assertEquals size assertEquals size processQueue assertEquals size verify collect map stream listFiles getAbsolutePath replace getAbsolutePath toList assertEquals size assertTrue contains assertTrue contains assertTrue contains of of of listFiles getAbsolutePath getValidHandlerKeys assertEquals size assertTrue contains assertTrue contains assertTrue contains getValidHandlerKeys assertEquals size assertTrue contains assertTrue contains getValidHandlerKeys assertEquals size assertTrue contains
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testQueueExporter()
focal_class.declarator: logger = Logger.getLogger(QueueExporter.class.getCanonicalName())
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = Logger.getLogger(QueueExporter.class.getCanonicalName());
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: FILENAME =
        Pattern.compile("^(.*)\\.(\\w+)\\.(\\w+)\\.(\\w+)\\.(\\w+)$")
focal_class.modifier: private static final
focal_class.original_string: private static final Pattern FILENAME =
        Pattern.compile("^(.*)\\.(\\w+)\\.(\\w+)\\.(\\w+)\\.(\\w+)$");
focal_class.type: Pattern
focal_class.var_name: FILENAME
focal_class.declarator: config
focal_class.modifier: private final
focal_class.original_string: private final ProxyConfig config;
focal_class.type: ProxyConfig
focal_class.var_name: config
focal_class.declarator: taskQueueFactory
focal_class.modifier: private final
focal_class.original_string: private final TaskQueueFactory taskQueueFactory;
focal_class.type: TaskQueueFactory
focal_class.var_name: taskQueueFactory
focal_class.declarator: entityPropertiesFactory
focal_class.modifier: private final
focal_class.original_string: private final EntityPropertiesFactory entityPropertiesFactory;
focal_class.type: EntityPropertiesFactory
focal_class.var_name: entityPropertiesFactory
focal_class.file: proxy/src/main/java/com/wavefront/agent/queueing/QueueExporter.java
focal_class.identifier: QueueExporter
focal_class.class_method_signature: QueueExporter.QueueExporter(ProxyConfig config, TaskQueueFactory taskQueueFactory,
                         EntityPropertiesFactory entityPropertiesFactory)
focal_class.full_signature: public  QueueExporter(ProxyConfig config, TaskQueueFactory taskQueueFactory,
                         EntityPropertiesFactory entityPropertiesFactory)
focal_class.identifier: QueueExporter
focal_class.modifiers: public
focal_class.parameters: (ProxyConfig config, TaskQueueFactory taskQueueFactory,
                         EntityPropertiesFactory entityPropertiesFactory)
focal_class.signature:  QueueExporter(ProxyConfig config, TaskQueueFactory taskQueueFactory,
                         EntityPropertiesFactory entityPropertiesFactory)
focal_class.class_method_signature: QueueExporter.export()
focal_class.full_signature: public void export()
focal_class.identifier: export
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void export()
focal_class.class_method_signature: QueueExporter.processHandlerKey(HandlerKey key)
focal_class.full_signature: @VisibleForTesting void processHandlerKey(HandlerKey key)
focal_class.identifier: processHandlerKey
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: (HandlerKey key)
focal_class.return: void
focal_class.signature: void processHandlerKey(HandlerKey key)
focal_class.class_method_signature: QueueExporter.processQueue(TaskQueue<T> queue,
                                                        BufferedWriter writer)
focal_class.full_signature: @VisibleForTesting void processQueue(TaskQueue<T> queue,
                                                        BufferedWriter writer)
focal_class.identifier: processQueue
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: (TaskQueue<T> queue,
                                                        BufferedWriter writer)
focal_class.return: void
focal_class.signature: void processQueue(TaskQueue<T> queue,
                                                        BufferedWriter writer)
focal_class.class_method_signature: QueueExporter.processTask(T task, BufferedWriter writer)
focal_class.full_signature: @VisibleForTesting void processTask(T task, BufferedWriter writer)
focal_class.identifier: processTask
focal_class.modifiers: @VisibleForTesting
focal_class.parameters: (T task, BufferedWriter writer)
focal_class.return: void
focal_class.signature: void processTask(T task, BufferedWriter writer)
focal_class.class_method_signature: QueueExporter.getValidHandlerKeys(List<String> files, String portList)
focal_class.full_signature: @VisibleForTesting static Set<HandlerKey> getValidHandlerKeys(List<String> files, String portList)
focal_class.identifier: getValidHandlerKeys
focal_class.modifiers: @VisibleForTesting static
focal_class.parameters: (List<String> files, String portList)
focal_class.return: Set<HandlerKey>
focal_class.signature: Set<HandlerKey> getValidHandlerKeys(List<String> files, String portList)
focal_class.class_method_signature: QueueExporter.listFiles(String buffer)
focal_class.full_signature: @VisibleForTesting static List<String> listFiles(String buffer)
focal_class.identifier: listFiles
focal_class.modifiers: @VisibleForTesting static
focal_class.parameters: (String buffer)
focal_class.return: List<String>
focal_class.signature: List<String> listFiles(String buffer)
focal_method.body: public QueueExporter(ProxyConfig config, TaskQueueFactory taskQueueFactory,
                         EntityPropertiesFactory entityPropertiesFactory) {
      this.config = config;
      this.taskQueueFactory = taskQueueFactory;
      this.entityPropertiesFactory = entityPropertiesFactory;
    }
focal_method.class_method_signature: QueueExporter.QueueExporter(ProxyConfig config, TaskQueueFactory taskQueueFactory,
                         EntityPropertiesFactory entityPropertiesFactory)
focal_method.full_signature: public  QueueExporter(ProxyConfig config, TaskQueueFactory taskQueueFactory,
                         EntityPropertiesFactory entityPropertiesFactory)
focal_method.identifier: QueueExporter
focal_method.modifiers: public
focal_method.parameters: (ProxyConfig config, TaskQueueFactory taskQueueFactory,
                         EntityPropertiesFactory entityPropertiesFactory)
focal_method.signature:  QueueExporter(ProxyConfig config, TaskQueueFactory taskQueueFactory,
                         EntityPropertiesFactory entityPropertiesFactory)