Esempio n. 1
0
 /**
  * Test that point features are rendered at the expected image coordinates when the map is
  * rotated. StreamingRenderer
  *
  * @throws Exception
  */
 @Test
 public void testRotatedTransform() throws Exception {
   // If we rotate the world rectangle + 90 degrees around (0,0), we get the screen rectangle
   final Rectangle screen = new Rectangle(0, 0, 100, 50);
   final Envelope world = new Envelope(0, 50, 0, -100);
   final AffineTransform worldToScreen =
       AffineTransform.getRotateInstance(Math.toRadians(90), 0, 0);
   DefaultFeatureCollection fc = new DefaultFeatureCollection();
   fc.add(createPoint(0, 0));
   fc.add(createPoint(world.getMaxX(), world.getMinY()));
   MapContext mapContext = new DefaultMapContext(DefaultGeographicCRS.WGS84);
   mapContext.addLayer((FeatureCollection) fc, createPointStyle());
   BufferedImage image =
       new BufferedImage(screen.width, screen.height, BufferedImage.TYPE_4BYTE_ABGR);
   final StreamingRenderer sr = new StreamingRenderer();
   sr.setContext(mapContext);
   sr.paint(image.createGraphics(), screen, worldToScreen);
   assertTrue("Pixel should be drawn at 0,0 ", image.getRGB(0, 0) != 0);
   assertTrue(
       "Pixel should not be drawn in image centre ",
       image.getRGB(screen.width / 2, screen.height / 2) == 0);
   assertTrue(
       "Pixel should be drawn at image max corner ",
       image.getRGB(screen.width - 1, screen.height - 1) != 0);
 }
Esempio n. 2
0
  @Test
  public void testOverTcp() throws IOException, InterruptedException {
    String name = TMP + "/testOverTcp0";
    String name2 = TMP + "/testOverTcp2";
    ChronicleTools.deleteOnExit(name);
    ChronicleTools.deleteOnExit(name2);

    long start = System.nanoTime();
    int PORT = 12345;
    int size = 0;

    InProcessChronicleSource chronicle =
        new InProcessChronicleSource(new IndexedChronicle(name), PORT);
    DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
    MapWrapper<String, String> strings =
        new MapWrapper<String, String>(
            dataStore,
            "strings",
            String.class,
            String.class,
            new LinkedHashMap<String, String>(),
            16);
    MapWrapper<Integer, Integer> ints =
        new MapWrapper<Integer, Integer>(
            dataStore,
            "ints",
            Integer.class,
            Integer.class,
            new LinkedHashMap<Integer, Integer>(),
            16);
    dataStore.start();
    ints.clear();
    strings.clear();

    InProcessChronicleSink chronicle2 =
        new InProcessChronicleSink(new IndexedChronicle(name2), "localhost", PORT);
    DataStore dataStore2 = new DataStore(chronicle2, ModelMode.READ_ONLY);
    MapWrapper<String, String> strings2 =
        new MapWrapper<String, String>(
            dataStore2,
            "strings",
            String.class,
            String.class,
            new LinkedHashMap<String, String>(),
            16);
    MapWrapper<Integer, Integer> ints2 =
        new MapWrapper<Integer, Integer>(
            dataStore2,
            "ints",
            Integer.class,
            Integer.class,
            new LinkedHashMap<Integer, Integer>(),
            16);

    final AtomicInteger sai = new AtomicInteger();
    MapListener<String, String> stringsListener =
        new AbstractMapListener<String, String>() {
          @Override
          public void update(String key, String oldValue, String newValue) {
            //                System.out.println(key + " " + oldValue + " => " + newValue);
            sai.incrementAndGet();
          }
        };
    strings2.addListener(stringsListener);

    final AtomicInteger iai = new AtomicInteger();
    MapListener<Integer, Integer> intsListener =
        new AbstractMapListener<Integer, Integer>() {
          @Override
          public void update(Integer key, Integer oldValue, Integer newValue) {
            //                System.out.println(key + " " + oldValue + " => " + newValue);
            iai.incrementAndGet();
          }
        };
    ints2.addListener(intsListener);
    dataStore2.start();

    int count = 0;
    for (int j = 0; j < 1000; j++) {
      int collectionSize = 1000;
      for (int i = 0; i < collectionSize; i++) {
        ints.put(i, i + j);
        strings.put(Integer.toString(i), Integer.toString(i + j));
      }
      size += Math.min(strings.size(), ints.size());
      for (int i = 0; i < collectionSize; i++) {
        ints.remove(i);
        strings.remove(Integer.toString(i));
      }
      count += 4 * collectionSize;
    }
    long mid = System.nanoTime();

    //        int timeout = 0;
    while (dataStore2.events() < count) {
      //            if (timeout++ % 10000 == 0)
      //                System.out.println(dataStore2.events());
      dataStore2.nextEvent();
    }

    chronicle.close();
    chronicle2.close();
    long end = System.nanoTime();

    System.out.printf(
        "Startup and write took %.2f us on average and read and shutdown took %.2f on average%n",
        (mid - start) / count / 1e3, (end - mid) / count / 1e3);
  }
Esempio n. 3
0
  @Test
  public void testMapPerformance() throws IOException {
    String name = TMP + "/map-perf";
    ChronicleTools.deleteOnExit(name);
    long start = System.nanoTime();
    int size = 0;
    {
      Chronicle chronicle = new IndexedChronicle(name);
      DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
      MapWrapper<String, String> strings =
          new MapWrapper<String, String>(
              dataStore,
              "strings",
              String.class,
              String.class,
              new LinkedHashMap<String, String>(),
              16);
      MapWrapper<Integer, Integer> ints =
          new MapWrapper<Integer, Integer>(
              dataStore,
              "ints",
              Integer.class,
              Integer.class,
              new LinkedHashMap<Integer, Integer>(),
              16);
      dataStore.start();
      ints.clear();
      strings.clear();

      for (int j = 0; j < 10000; j++) {
        for (int i = 0; i < 100; i++) {
          ints.put(i, i + j);
          strings.put(Integer.toString(i), Integer.toString(i + j));
        }
        size += Math.min(strings.size(), ints.size());
        for (int i = 0; i < 100; i++) {
          ints.remove(i);
          strings.remove(Integer.toString(i));
        }
      }

      chronicle.close();
    }
    long mid = System.nanoTime();
    {
      Chronicle chronicle = new IndexedChronicle(name);
      DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER);
      MapWrapper<String, String> strings =
          new MapWrapper<String, String>(
              dataStore,
              "strings",
              String.class,
              String.class,
              new LinkedHashMap<String, String>(),
              16);
      MapWrapper<Integer, Integer> ints =
          new MapWrapper<Integer, Integer>(
              dataStore,
              "ints",
              Integer.class,
              Integer.class,
              new LinkedHashMap<Integer, Integer>(),
              16);
      dataStore.start();
      chronicle.close();
    }
    long end = System.nanoTime();
    System.out.printf(
        "Took %.1f seconds avg to add&remove %,d elements and %.1f seconds avg to reload them%n",
        (mid - start) / 2e9, size, (end - mid) / 2e9);
  }