@Before
  public void setup() throws IOException {

    final TcpTransportAndNetworkConfig tcpConfig =
        TcpTransportAndNetworkConfig.of(8076, new InetSocketAddress("localhost", 8077))
            .heartBeatInterval(1, SECONDS)
            .autoReconnectedUponDroppedConnection(true);

    map1 =
        ChronicleMapBuilder.of(Integer.class, CharSequence.class)
            .entries(20000)
            .replication((byte) 1, tcpConfig)
            .create();

    TcpTransportAndNetworkConfig config2 =
        TcpTransportAndNetworkConfig.of(8077)
            .heartBeatInterval(1, SECONDS)
            .autoReconnectedUponDroppedConnection(true);

    map2 =
        ChronicleMapBuilder.of(Integer.class, CharSequence.class)
            .entries(20000)
            .replication((byte) 2, config2)
            .create();
  }
  /**
   * Test that both maps are created first and then populated the first map so that second will get
   * the contents
   *
   * @throws Exception
   */
  @Test
  public void testReplicatedMap() throws Exception {

    TcpTransportAndNetworkConfig tcpTransportAndNetworkConfig =
        TcpTransportAndNetworkConfig.of(8076).heartBeatInterval(1L, TimeUnit.SECONDS);

    TcpTransportAndNetworkConfig tcpTransportAndNetworkConfig1 =
        TcpTransportAndNetworkConfig.of(8077, new InetSocketAddress("127.0.0.1", 8076))
            .heartBeatInterval(1L, TimeUnit.SECONDS);

    try (ChronicleMap<CharSequence, TestInstrumentVOInterface> map =
            ChronicleMapBuilder.of(CharSequence.class, TestInstrumentVOInterface.class)
                .entries(5000L)
                .averageKeySize(10)
                .replication((byte) 1, tcpTransportAndNetworkConfig)
                .create();
        ChronicleMap<CharSequence, TestInstrumentVOInterface> replicatedMap =
            ChronicleMapBuilder.of(CharSequence.class, TestInstrumentVOInterface.class)
                .putReturnsNull(true)
                .removeReturnsNull(true)
                .entries(5000L)
                .averageKeySize(10)
                .replication((byte) 2, tcpTransportAndNetworkConfig1)
                .create()) {
      // Store some data into MAP1
      TestInstrumentVOInterface intrumentVOInterface = map.newValueInstance();

      try (Closeable c = map.acquireContext("KEY1", intrumentVOInterface)) {
        intrumentVOInterface.setSymbol("Flyer");
        intrumentVOInterface.setCurrencyCode("USA");
        intrumentVOInterface.setSizeOfInstrumentIDArray(2);

        //   TestIntrumentVOInterface.TestInstrumentIDVOInterface instrumentIDVOInterface =
        intrumentVOInterface.getInstrumentIDAt(0);
        //   instrumentIDVOInterface.setIdSource("CUSIP");
        //   instrumentIDVOInterface.setSecurityId("TEST");

        // intrumentVOInterface.setInstrumentIDAt(0, instrumentIDVOInterface);

        //  Assert.assertNotNull(map);
        //  Assert.assertNotNull(replicatedMap);
      }

      Builder.waitTillEqual(map, replicatedMap, 5000);

      Assert.assertEquals(map, replicatedMap);
      Assert.assertTrue(!replicatedMap.isEmpty());

      System.out.println(replicatedMap.get("KEY1"));
    }
  }
예제 #3
0
  public static void main(String[] args) throws Exception {

    MAP_FILE_A.delete();
    MAP_FILE_B.delete();

    ChronicleMapBuilder<String, Long> cityPostalCodesMapBuilder =
        ChronicleMapBuilder.of(String.class, Long.class)
            // .averageKeySize(100)
            .averageKey(STR)
            .replication(
                (byte) 1,
                TcpTransportAndNetworkConfig.of(8076, new InetSocketAddress("localhost", 8077))
                    .heartBeatInterval(1, TimeUnit.SECONDS))
            .entries(50_000);

    ChronicleMap<String, Long> cityPostalCodes =
        cityPostalCodesMapBuilder.createPersistedTo(MAP_FILE_A);

    for (int i = 0; i < 100; i++) {
      cityPostalCodes.put(STR + i, Long.valueOf(i));
    }

    LOGGER.info("Map created");
    Thread.sleep(10000);
    System.exit(0);
  }
  @Before
  public void setup() throws IOException {
    value = DataValueClasses.newDirectReference(IntValue.class);
    ((Byteable) value).bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);

    final InetSocketAddress endpoint = new InetSocketAddress("localhost", s_port + 1);
    timeProvider =
        new TimeProvider() {

          Random rnd = new Random(4);

          @Override
          public long currentTime() {

            if (rnd.nextBoolean()) return t++;
            else return t;
          }
        };

    {
      final TcpTransportAndNetworkConfig tcpConfig1 =
          TcpTransportAndNetworkConfig.of(s_port, endpoint);

      map1 =
          ChronicleMapBuilder.of(Integer.class, CharSequence.class)
              .entries(Builder.SIZE)
              .timeProvider(timeProvider)
              .replication((byte) 1, tcpConfig1)
              .create();
    }
    {
      final TcpTransportAndNetworkConfig tcpConfig2 = TcpTransportAndNetworkConfig.of(s_port + 1);

      map2 =
          ChronicleMapBuilder.of(Integer.class, CharSequence.class)
              .entries(Builder.SIZE)
              .timeProvider(timeProvider)
              .replication((byte) 2, tcpConfig2)
              .create();
    }
    s_port += 2;
  }
  protected ChronicleMap createReplicatedMap1() {

    ChronicleMap chronicleMap = null;
    TcpTransportAndNetworkConfig tcpTransportAndNetworkConfig =
        TcpTransportAndNetworkConfig.of(8076).heartBeatInterval(1L, TimeUnit.SECONDS);
    try {
      ChronicleMapBuilder builder =
          ChronicleMapBuilder.of(CharSequence.class, TestInstrumentVOInterface.class)
              .entries(5000L)
              .averageKeySize(10)
              .replication((byte) 1, tcpTransportAndNetworkConfig);

      chronicleMap = builder.create();

    } catch (Exception e) {
      System.out.println("Error(s) creating instrument cache: " + e);
    }
    return chronicleMap;
  }
  protected ChronicleMap createReplicatedMap2() {

    ChronicleMap chronicleMap = null;
    TcpTransportAndNetworkConfig tcpTransportAndNetworkConfig =
        TcpTransportAndNetworkConfig.of(8077, new InetSocketAddress("127.0.0.1", 8076))
            .heartBeatInterval(1L, TimeUnit.SECONDS);

    try {
      ChronicleMapBuilder builder =
          ChronicleMapBuilder.of(CharSequence.class, TestInstrumentVOInterface.class)
              .putReturnsNull(true)
              .removeReturnsNull(true)
              .entries(5000L)
              .averageKeySize(10)
              .replication((byte) 2, tcpTransportAndNetworkConfig);

      chronicleMap = builder.create();

    } catch (Exception e) {
      System.out.println(
          "*********************Error(s) creating launcher " + "instrument cache: " + e);
    }
    return chronicleMap;
  }