Java 类com.amazonaws.services.dynamodbv2.local.main.ServerRunner 实例源码

项目:AssortmentOfJUnitRules    文件:HttpDynamoDbRule.java   
@Override
protected void before() throws Throwable {
  nativeLibraryRule.before();
  System.setProperty("sqlite4java.library.path", nativeLibraryRule.getNativeLibrariesFolder().toString());

  if (useFakeCreds) {
    System.setProperty("aws.accessKeyId", "x");
    System.setProperty("aws.secretKey", "x");
  }

  if(defaultPort > -1) {
    port = defaultPort;
  } else {
    port = Helper.findRandomOpenPortOnAllLocalInterfaces();
  }


  final String[] localArgs = { "-inMemory", "-port", Integer.toString(port) };
  server = ServerRunner.createServerFromCommandLineArgs(localArgs);
  server.start();
}
项目:elo-api    文件:LeagueDaoTest.java   
@Test
public void testFindOne() throws Exception {
    AWSCredentials credentials = new BasicAWSCredentials("qwe", "qwe");
    AmazonDynamoDB client = new AmazonDynamoDBClient(credentials);

    client.setEndpoint("http://localhost:3210");

    DynamoDbClientFactory clientFactory = Mockito.mock(DynamoDbClientFactory.class);
    Mockito.when(clientFactory.client()).thenReturn(client);


    SQLite.setLibraryPath((this.getClass().getClassLoader().getResource("lib").getPath()));
    final String[] localArgs = {"-inMemory", "-port", "3210"};
    DynamoDBProxyServer server = ServerRunner.createServerFromCommandLineArgs(localArgs);
    server.start();

    log.info("tables: ");
    client.listTables().getTableNames().forEach(log::info);

    UUID uuid = UUID.randomUUID();
    LeagueRecord record = LeagueRecord.builder()
            .id(uuid.toString())
            .name("foosball singles")
            .teamSize(1).build();

    LeagueDao instance = new LeagueDao(clientFactory);
    LeagueRecord created = instance.create(record);
    log.info("created league record:" + created.toString());
    LeagueRecord actual = instance.findOne(uuid.toString());

    Assert.assertEquals(record, actual);
    server.stop();
}
项目:elo-api    文件:LeagueDaoTest.java   
@Test
public void testFindByType() throws Exception {
    AWSCredentials credentials = new BasicAWSCredentials("qwe", "qwe");
    AmazonDynamoDB client = new AmazonDynamoDBClient(credentials);

    client.setEndpoint("http://localhost:3210");

    DynamoDbClientFactory clientFactory = Mockito.mock(DynamoDbClientFactory.class);
    Mockito.when(clientFactory.client()).thenReturn(client);


    SQLite.setLibraryPath((this.getClass().getClassLoader().getResource("lib").getPath()));
    final String[] localArgs = {"-inMemory", "-port", "3210"};
    DynamoDBProxyServer server = ServerRunner.createServerFromCommandLineArgs(localArgs);
    server.start();

    log.info("tables: ");
    client.listTables().getTableNames().forEach(log::info);

    UUID uuid = UUID.randomUUID();
    LeagueRecord record = LeagueRecord.builder()
            .id(uuid.toString())
            .name("foosball singles")
            .gameType(GameType.FOOSBALL)
            .teamSize(1).build();

    LeagueDao instance = new LeagueDao(clientFactory);
    LeagueRecord created = instance.create(record);
    log.info("created league record:" + created.toString());
    List<LeagueRecord> actuals = instance.byType(record.getGameType());

    LeagueRecord actual = actuals.get(0);
    log.info("expected: " + record.toString());
    log.info("actual:   " + actual.toString());
    Assert.assertEquals("has same id", record.getId(), actual.getId());
    Assert.assertNull("lookup does not have name data", actual.getName());
    Assert.assertEquals("has same game type", record.getGameType(), actual.getGameType());
    server.stop();
}
项目:drill-dynamo-adapter    文件:LocalDynamoTestUtil.java   
public void start() throws Exception {
  // create a local database instance with an local server url on an open port
  ServerSocket socket = new ServerSocket(0);
  port = socket.getLocalPort();
  socket.close();

  final String[] localArgs = {"-inMemory", "-port", String.valueOf(port)};
  server = ServerRunner.createServerFromCommandLineArgs(localArgs);
  server.start();
  url = "http://localhost:" + port;

  // internal client connection so we can easily stop, cleanup, etc. later
  this.dynamodb = getClient();
}
项目:aws-dynamodb-examples    文件:DynamoDBLocalFixture.java   
/**
 * You can use mvn to run DynamoDBLocalFixture, e.g.
 * <p>
 * $ mvn clean package
 * <p>
 * $ mvn exec:java -Dexec.mainClass="com.amazonaws.services.dynamodbv2.DynamoDBLocalFixture" \
 * -Dexec.classpathScope="test" \
 * -Dsqlite4java.library.path=target/dependencies
 * <p>
 * It's recommended to run "aws configure" one time before you run DynamoDBLocalFixture
 *
 * @param args - no args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    AmazonDynamoDB dynamodb = null;
    try {
        // Create an in-memory and in-process instance of DynamoDB Local that skips HTTP
        dynamodb = DynamoDBEmbedded.create().amazonDynamoDB();
        // use the DynamoDB API with DynamoDBEmbedded
        listTables(dynamodb.listTables(), "DynamoDB Embedded");
    } finally {
        // Shutdown the thread pools in DynamoDB Local / Embedded
        if(dynamodb != null) {
            dynamodb.shutdown();
        }
    }

    // Create an in-memory and in-process instance of DynamoDB Local that runs over HTTP
    final String[] localArgs = { "-inMemory" };
    DynamoDBProxyServer server = null;
    try {
        server = ServerRunner.createServerFromCommandLineArgs(localArgs);
        server.start();

        dynamodb = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(
            // we can use any region here
            new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2"))
            .build();

        // use the DynamoDB API over HTTP
        listTables(dynamodb.listTables(), "DynamoDB Local over HTTP");
    } finally {
        // Stop the DynamoDB Local endpoint
        if(server != null) {
            server.stop();
        }
    }
}