org.apache.distributedlog.api.namespace.Namespace Java Examples

The following examples show how to use org.apache.distributedlog.api.namespace.Namespace. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SinkApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function registration interrupted")
public void testUpdateSinkInterrupted() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadFileToBookkeeper(
                anyString(),
                any(File.class),
                any(Namespace.class));
        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(sink))).thenReturn(true);

        doThrow(new IllegalStateException("Function registration interrupted"))
                .when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), Mockito.anyBoolean());

        updateDefaultSink();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
 
Example #2
Source File: FunctionApiV2ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "upload failure")
public void testRegisterFunctionUploadFailure() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doThrow(new IOException("upload failure")).when(WorkerUtils.class);

        WorkerUtils.uploadFileToBookkeeper(
                anyString(),
                any(File.class),
                any(Namespace.class));
        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);

        registerDefaultFunction();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
 
Example #3
Source File: SourceApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Update contains no change")
public void testUpdateSourceMissingPackage() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.downloadFromBookkeeper(any(Namespace.class), any(File.class), anyString());

        testUpdateSourceMissingArguments(
            tenant,
            namespace,
                source,
                null,
            mockedFormData,
            outputTopic,
                outputSerdeClassName,
            null,
            parallelism,
                "Update contains no change");
    } catch (RestException re){
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
        throw re;
    }
}
 
Example #4
Source File: FunctionApiV2ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateFunctionChangedInputs() throws Exception {
    mockStatic(WorkerUtils.class);
    doNothing().when(WorkerUtils.class);
    WorkerUtils.downloadFromBookkeeper(any(Namespace.class), any(File.class), anyString());
    PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

    testUpdateFunctionMissingArguments(
            tenant,
            namespace,
            function,
            null,
            topicsToSerDeClassName,
            mockedFormData,
            "DifferentOutput",
            outputSerdeClassName,
            null,
            parallelism,
            null);
}
 
Example #5
Source File: FunctionApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "upload failure")
public void testRegisterFunctionUploadFailure() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doThrow(new IOException("upload failure")).when(WorkerUtils.class);

        WorkerUtils.uploadFileToBookkeeper(
                anyString(),
            any(File.class),
            any(Namespace.class));
        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);

        registerDefaultFunction();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
 
Example #6
Source File: FunctionApiV2ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegisterFunctionSuccess() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadToBookeeper(
                any(Namespace.class),
                any(InputStream.class),
                anyString());
        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);

        registerDefaultFunction();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
        throw re;
    }
}
 
Example #7
Source File: SourceApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSourceChangedTopic() throws Exception {
    mockStatic(WorkerUtils.class);
    doNothing().when(WorkerUtils.class);
    WorkerUtils.downloadFromBookkeeper(any(Namespace.class), any(File.class), anyString());

    testUpdateSourceMissingArguments(
            tenant,
            namespace,
            source,
            null,
            mockedFormData,
            "DifferentTopic",
            outputSerdeClassName,
            className,
            parallelism,
            null);
}
 
Example #8
Source File: FunctionApiV2ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function registration interrupted")
public void testRegisterFunctionInterrupted() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadToBookeeper(
                any(Namespace.class),
                any(InputStream.class),
                anyString());
        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);

        doThrow(new IllegalStateException("Function registration interrupted"))
                .when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), anyBoolean());
        registerDefaultFunction();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
 
Example #9
Source File: FunctionApiV2ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Update contains no change")
public void testUpdateFunctionMissingInputTopic() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.downloadFromBookkeeper(any(Namespace.class), any(File.class), anyString());
        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        testUpdateFunctionMissingArguments(
                tenant,
                namespace,
                function,
                null,
                null,
                mockedFormData,
                outputTopic,
                outputSerdeClassName,
                className,
                parallelism,
                "Update contains no change");
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
        throw re;
    }
}
 
Example #10
Source File: DlogUploaderTest.java    From incubator-heron with Apache License 2.0 6 votes vote down vote up
@Test
public void testUploadPackageExisting() throws Exception {
  uploader = Mockito.spy(uploader);

  Namespace ns = mock(Namespace.class);
  when(nsBuilder.build()).thenReturn(ns);
  when(ns.logExists(anyString())).thenReturn(true);
  DistributedLogManager dlm = mock(DistributedLogManager.class);
  when(ns.openLog(anyString())).thenReturn(dlm);
  AppendOnlyStreamWriter asw = mock(AppendOnlyStreamWriter.class);
  when(dlm.getAppendOnlyStreamWriter()).thenReturn(asw);

  Mockito.doReturn(true).when(uploader).isLocalFileExists(Mockito.anyString());

  uploader.initialize(config);
  uploader.uploadPackage();

  verify(ns, times(1)).deleteLog(eq(uploader.getPackageName()));
  verify(copier, times(1))
      .copyFileToStream(eq(uploader.getTopologyPackageLocation()), any(OutputStream.class));
  verify(asw, times(1)).close();
  verify(dlm, times(1)).close();
}
 
Example #11
Source File: FunctionApiV2ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function registeration interrupted")
public void testUpdateFunctionInterrupted() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadToBookeeper(
                any(Namespace.class),
                any(InputStream.class),
                anyString());

        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();


        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);

        doThrow(new IllegalStateException("Function registeration interrupted"))
                .when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), anyBoolean());

        updateDefaultFunction();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
 
Example #12
Source File: SinkApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "sink failed to register")
public void testUpdateSinkFailure() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadFileToBookkeeper(
                anyString(),
                any(File.class),
                any(Namespace.class));
        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(sink))).thenReturn(true);

        doThrow(new IllegalArgumentException("sink failed to register"))
                .when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), Mockito.anyBoolean());

        updateDefaultSink();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
        throw re;
    }
}
 
Example #13
Source File: DistributedLogTool.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
protected void printStreams(Namespace namespace) throws Exception {
    Iterator<String> streams = namespace.getLogs();
    System.out.println("Streams under " + getUri() + " : ");
    System.out.println("--------------------------------");
    while (streams.hasNext()) {
        String streamName = streams.next();
        System.out.println(streamName);
        if (!printMetadata) {
            continue;
        }
        MetadataAccessor accessor =
                namespace.getNamespaceDriver().getMetadataAccessor(streamName);
        byte[] metadata = accessor.getMetadata();
        if (null == metadata || metadata.length == 0) {
            continue;
        }
        if (printHex) {
            System.out.println(Hex.encodeHexString(metadata));
        } else {
            System.out.println(new String(metadata, UTF_8));
        }
        System.out.println("");
    }
    System.out.println("--------------------------------");
}
 
Example #14
Source File: FunctionApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function registration interrupted")
public void testRegisterFunctionInterrupted() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadToBookeeper(
            any(Namespace.class),
            any(InputStream.class),
            anyString());

        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);

        doThrow(new IllegalStateException("Function registration interrupted"))
                .when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), Mockito.anyBoolean());

        registerDefaultFunction();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
 
Example #15
Source File: DistributedLogTool.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private void truncateStreams(Namespace namespace, List<String> streams,
                             int tid, int numStreamsPerThreads) throws IOException {
    int startIdx = tid * numStreamsPerThreads;
    int endIdx = Math.min(streams.size(), (tid + 1) * numStreamsPerThreads);
    for (int i = startIdx; i < endIdx; i++) {
        String s = streams.get(i);
        DistributedLogManager dlm = namespace.openLog(s);
        try {
            if (deleteStream) {
                dlm.delete();
            } else {
                dlm.purgeLogsOlderThan(Long.MAX_VALUE);
            }
        } finally {
            dlm.close();
        }
    }
}
 
Example #16
Source File: SinkApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSinkDifferentParallelism() throws Exception {
    mockStatic(WorkerUtils.class);
    doNothing().when(WorkerUtils.class);
    WorkerUtils.downloadFromBookkeeper(any(Namespace.class), any(File.class), anyString());

    PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

    testUpdateSinkMissingArguments(
            tenant,
            namespace,
            sink,
            null,
            mockedFormData,
            topicsToSerDeClassName,
            className,
            parallelism + 1,
            null);
}
 
Example #17
Source File: DLAuditor.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private void collectLedgersFromDL(final URI uri,
                                  final Namespace namespace,
                                  final Set<Long> ledgers) throws IOException {
    logger.info("Enumerating {} to collect streams.", uri);
    Iterator<String> streams = namespace.getLogs();
    final LinkedBlockingQueue<String> streamQueue = new LinkedBlockingQueue<String>();
    while (streams.hasNext()) {
        streamQueue.add(streams.next());
    }

    logger.info("Collected {} streams from uri {} : {}",
                new Object[] { streamQueue.size(), uri, streams });

    executeAction(streamQueue, 10, new Action<String>() {
        @Override
        public void execute(String stream) throws IOException {
            collectLedgersFromStream(namespace, stream, ledgers);
        }
    });
}
 
Example #18
Source File: DLAuditor.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private List<Long> collectLedgersFromStream(Namespace namespace,
                                            String stream,
                                            Set<Long> ledgers)
        throws IOException {
    DistributedLogManager dlm = namespace.openLog(stream);
    try {
        List<LogSegmentMetadata> segments = dlm.getLogSegments();
        List<Long> sLedgers = new ArrayList<Long>();
        for (LogSegmentMetadata segment : segments) {
            synchronized (ledgers) {
                ledgers.add(segment.getLogSegmentId());
            }
            sLedgers.add(segment.getLogSegmentId());
        }
        return sLedgers;
    } finally {
        dlm.close();
    }
}
 
Example #19
Source File: SourceApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "source failed to register")
public void testRegisterSourceFailure() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadFileToBookkeeper(
                anyString(),
                any(File.class),
                any(Namespace.class));

        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(source))).thenReturn(false);

        doThrow(new IllegalArgumentException("source failed to register"))
                .when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), Mockito.anyBoolean());

        registerDefaultSource();
    } catch (RestException re){
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
        throw re;
    }
}
 
Example #20
Source File: SourceApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function registration interrupted")
public void testUpdateSourceInterrupted() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadFileToBookkeeper(
                anyString(),
                any(File.class),
                any(Namespace.class));

        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(source))).thenReturn(true);

        doThrow(new IllegalStateException("Function registration interrupted"))
                .when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), Mockito.anyBoolean());

        updateDefaultSource();
    } catch (RestException re){
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
 
Example #21
Source File: SinkApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Update contains no change")
public void testUpdateSinkMissingPackage() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.downloadFromBookkeeper(any(Namespace.class), any(File.class), anyString());

        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        testUpdateSinkMissingArguments(
            tenant,
            namespace,
                sink,
            null,
            mockedFormData,
            topicsToSerDeClassName,
            null,
            parallelism,
                "Update contains no change");
    } catch (RestException re){
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
        throw re;
    }
}
 
Example #22
Source File: SourceApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function registration interrupted")
public void testRegisterSourceInterrupted() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadFileToBookkeeper(
                anyString(),
                any(File.class),
                any(Namespace.class));

        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(source))).thenReturn(false);

        doThrow(new IllegalStateException("Function registration interrupted"))
                .when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), Mockito.anyBoolean());

        registerDefaultSource();
    } catch (RestException re){
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
 
Example #23
Source File: DlogUploaderTest.java    From incubator-heron with Apache License 2.0 6 votes vote down vote up
@Test
public void testUploadPackageLocalFileNotExist() throws Exception {
  uploader = Mockito.spy(uploader);

  Namespace ns = mock(Namespace.class);
  when(nsBuilder.build()).thenReturn(ns);
  Mockito.doReturn(false).when(uploader).isLocalFileExists(Mockito.anyString());

  uploader.initialize(config);
  try {
    uploader.uploadPackage();
    fail("Should fail on uploading package");
  } catch (UploaderException ue) {
    // expected
  }
  verify(ns, never()).logExists(anyString());
}
 
Example #24
Source File: FunctionApiV2ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "upload failure")
public void testUpdateFunctionUploadFailure() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doThrow(new IOException("upload failure")).when(WorkerUtils.class);
        WorkerUtils.uploadFileToBookkeeper(
                anyString(),
                any(File.class),
                any(Namespace.class));
        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);

        updateDefaultFunction();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
 
Example #25
Source File: TestBKDistributedLogNamespace.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
private void createLogPathTest(String logName) throws Exception {
    URI uri = createDLMURI("/" + runtime.getMethodName());
    ensureURICreated(zooKeeperClient.get(), uri);
    DistributedLogConfiguration newConf = new DistributedLogConfiguration();
    newConf.addConfiguration(conf);
    newConf.setCreateStreamIfNotExists(false);
    Namespace namespace = NamespaceBuilder.newBuilder()
        .conf(newConf).uri(uri).build();
    DistributedLogManager dlm = namespace.openLog(logName);
    LogWriter writer;
    try {
        writer = dlm.startLogSegmentNonPartitioned();
        writer.write(DLMTestUtil.getLogRecordInstance(1L));
        writer.commit();
        fail("Should fail to write data if stream doesn't exist.");
    } catch (IOException ioe) {
        // expected
    }
    dlm.close();
}
 
Example #26
Source File: SinkApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "sink failed to register")
public void testRegisterSinkFailure() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadFileToBookkeeper(
                anyString(),
                any(File.class),
                any(Namespace.class));

        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(sink))).thenReturn(false);

        doThrow(new IllegalArgumentException("sink failed to register"))
                .when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), Mockito.anyBoolean());

        registerDefaultSink();
    } catch (RestException re){
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
        throw re;
    }
}
 
Example #27
Source File: SourceApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Source parallelism must be a positive number")
public void testUpdateSourceNegativeParallelism() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.downloadFromBookkeeper(any(Namespace.class), any(File.class), anyString());

        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        testUpdateSourceMissingArguments(
                tenant,
                namespace,
                source,
                null,
                mockedFormData,
                outputTopic,
                outputSerdeClassName,
                className,
                -2,
                "Source parallelism must be a positive number");
    } catch (RestException re){
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
        throw re;
    }
}
 
Example #28
Source File: FunctionApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Function registeration interrupted")
public void testUpdateFunctionInterrupted() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.uploadToBookeeper(
            any(Namespace.class),
            any(InputStream.class),
            anyString());
        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();

        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);

        doThrow(new IllegalStateException("Function registeration interrupted"))
                .when(mockedManager).updateFunctionOnLeader(any(FunctionMetaData.class), Mockito.anyBoolean());

        updateDefaultFunction();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
 
Example #29
Source File: FunctionApiV3ResourceTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "Update contains no change")
public void testUpdateFunctionMissingPackage() throws Exception {
    try {
        mockStatic(WorkerUtils.class);
        doNothing().when(WorkerUtils.class);
        WorkerUtils.downloadFromBookkeeper(any(Namespace.class), any(File.class), anyString());
        PowerMockito.when(WorkerUtils.class, "dumpToTmpFile", any()).thenCallRealMethod();
        testUpdateFunctionMissingArguments(
            tenant,
            namespace,
            function,
            null,
            topicsToSerDeClassName,
            mockedFormData,
            outputTopic,
                outputSerdeClassName,
            className,
            parallelism,
                "Update contains no change");
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
        throw re;
    }
}
 
Example #30
Source File: TestZKLogStreamMetadataStore.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testCreateLogMetadataWithCustomMetadata() throws Exception {
    String logName = testName.getMethodName();
    String logIdentifier = "<default>";
    List<String> pathsToDelete = Lists.newArrayList();

    DLMetadata.create(new BKDLConfig(zkServers, "/ledgers")).update(uri);

    Namespace namespace = NamespaceBuilder.newBuilder()
        .conf(new DistributedLogConfiguration())
        .uri(uri)
        .build();

    MetadataAccessor accessor = namespace.getNamespaceDriver().getMetadataAccessor(logName);
    accessor.createOrUpdateMetadata(logName.getBytes("UTF-8"));
    accessor.close();

    testCreateLogMetadataWithMissingPaths(uri, logName, logIdentifier, pathsToDelete, true, false);
}