當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectMetadata.setLastModified方法代碼示例

本文整理匯總了Java中com.amazonaws.services.s3.model.ObjectMetadata.setLastModified方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectMetadata.setLastModified方法的具體用法?Java ObjectMetadata.setLastModified怎麽用?Java ObjectMetadata.setLastModified使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.s3.model.ObjectMetadata的用法示例。


在下文中一共展示了ObjectMetadata.setLastModified方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testFirstCallToReceiveMessagesReturnsOneViaS3

import com.amazonaws.services.s3.model.ObjectMetadata; //導入方法依賴的package包/類
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsOneViaS3() throws UnsupportedEncodingException {
    final AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
    final AmazonS3Client s3 = Mockito.mock(AmazonS3Client.class);
    final String queueName = "queue";
    final String s3Id = "123";
    Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
    final String receiptHandle = "abc";
    Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any())).thenReturn(
            new ReceiveMessageResult().withMessages(new Message().withReceiptHandle(receiptHandle).withBody(s3Id)));
    final String bucketName = "bucket";
    Mockito.when(s3.doesObjectExist(bucketName, s3Id)).thenAnswer(x -> true);
    final S3Object s3Object = mock(S3Object.class);
    Mockito.when(s3Object.getObjectContent())
            .thenReturn(new S3ObjectInputStream(new StringInputStream("body1"), null));
    final ObjectMetadata om = new ObjectMetadata();
    om.setLastModified(new Date(1001));
    Mockito.when(s3Object.getObjectMetadata()).thenReturn(om);
    Mockito.when(s3.getObject(bucketName, s3Id)).thenReturn(s3Object);
    Sqs.queueName(queueName) //
            .sqsFactory(() -> sqs) //
            .bucketName("bucket") //
            .s3Factory(() -> s3) //
            .messages() //
            .doOnNext(SqsMessage::deleteMessage) //
            .map(m -> m.message()) //
            .doOnError(Throwable::printStackTrace) //
            .take(1) //
            .test() //
            .awaitDone(10, TimeUnit.SECONDS) //
            .assertComplete() //
            .assertValues("body1");
    final InOrder inorder = Mockito.inOrder(sqs, s3, s3Object);
    inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
    inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
    inorder.verify(s3, Mockito.times(1)).doesObjectExist(bucketName, s3Id);
    inorder.verify(s3, Mockito.times(1)).getObject(bucketName, s3Id);
    inorder.verify(s3Object, Mockito.times(1)).getObjectContent();
    inorder.verify(s3Object, Mockito.times(1)).getObjectMetadata();
    inorder.verify(s3, Mockito.times(1)).deleteObject(bucketName, s3Id);
    inorder.verify(sqs, Mockito.times(1)).deleteMessage(queueName, receiptHandle);
    inorder.verify(sqs, Mockito.times(1)).shutdown();
    inorder.verify(s3, Mockito.times(1)).shutdown();
    inorder.verifyNoMoreInteractions();
}
 
開發者ID:davidmoten,項目名稱:rxjava2-aws,代碼行數:46,代碼來源:SqsTest.java

示例2: testFirstCallToReceiveMessagesReturnsOneWithNoS3ObjectAndOneWithS3Object

import com.amazonaws.services.s3.model.ObjectMetadata; //導入方法依賴的package包/類
@Test(timeout = 50000000)
public void testFirstCallToReceiveMessagesReturnsOneWithNoS3ObjectAndOneWithS3Object()
        throws UnsupportedEncodingException {
    final AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
    final AmazonS3Client s3 = Mockito.mock(AmazonS3Client.class);
    final String queueName = "queue";
    final String s3Id = "123";
    final String s3Id2 = "124";
    Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
    final String receiptHandle = "abc";
    final String receiptHandle2 = "abc2";
    Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any()))
            .thenReturn(new ReceiveMessageResult()
                    .withMessages(new Message().withReceiptHandle(receiptHandle).withBody(s3Id)))
            .thenReturn(new ReceiveMessageResult()
                    .withMessages(new Message().withReceiptHandle(receiptHandle2).withBody(s3Id2)));
    final String bucketName = "bucket";
    Mockito.when(s3.doesObjectExist(bucketName, s3Id)).thenReturn(false);
    Mockito.when(s3.doesObjectExist(bucketName, s3Id2)).thenReturn(true);
    final S3Object s3Object = mock(S3Object.class);
    Mockito.when(s3Object.getObjectContent())
            .thenReturn(new S3ObjectInputStream(new StringInputStream("body2"), null));
    final ObjectMetadata om = new ObjectMetadata();
    om.setLastModified(new Date(1001));
    Mockito.when(s3Object.getObjectMetadata()).thenReturn(om);
    Mockito.when(s3.getObject(bucketName, s3Id2)).thenReturn(s3Object);
    Sqs.queueName(queueName) //
            .sqsFactory(() -> sqs) //
            .bucketName("bucket") //
            .s3Factory(() -> s3) //
            .messages() //
            .doOnNext(SqsMessage::deleteMessage) //
            .map(m -> m.message()) //
            .doOnError(Throwable::printStackTrace) //
            .take(1) //
            .test() //
            .awaitDone(10, TimeUnit.SECONDS) //
            .assertComplete() //
            .assertValues("body2");
    final InOrder inorder = Mockito.inOrder(sqs, s3, s3Object);
    inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
    inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
    inorder.verify(s3, Mockito.times(1)).doesObjectExist(bucketName, s3Id);
    inorder.verify(sqs, Mockito.times(1)).deleteMessage(queueName, receiptHandle);
    inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
    inorder.verify(s3, Mockito.times(1)).doesObjectExist(bucketName, s3Id2);
    inorder.verify(s3, Mockito.times(1)).getObject(bucketName, s3Id2);
    inorder.verify(s3Object, Mockito.times(1)).getObjectContent();
    inorder.verify(s3Object, Mockito.times(1)).getObjectMetadata();
    inorder.verify(s3, Mockito.times(1)).deleteObject(bucketName, s3Id2);
    inorder.verify(sqs, Mockito.times(1)).deleteMessage(queueName, receiptHandle2);
    inorder.verify(sqs, Mockito.times(1)).shutdown();
    inorder.verify(s3, Mockito.times(1)).shutdown();
    inorder.verifyNoMoreInteractions();
}
 
開發者ID:davidmoten,項目名稱:rxjava2-aws,代碼行數:56,代碼來源:SqsTest.java


注:本文中的com.amazonaws.services.s3.model.ObjectMetadata.setLastModified方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。