MaxCompute Emulator是一款轻量级工具,旨在模拟阿里云MaxCompute(原ODPS)服务的行为。它基于SQLite提供模拟环境,供无实际MaxCompute账户的用户测试功能。该工具特别适用于开发和测试场景,可解决MaxCompute资源访问受限或成本约束的问题。
当前项目处于pre-alpha阶段,已实现主要接口,包括但不限于:
1.** SQL相关接口 :支持SQL语句执行等相关操作 2. 表元数据相关接口 :支持表的创建、 schema 获取等元数据操作 3. Tunnel upsert接口 **:支持Tunnel相关的upsert操作
-** 开发环境 :在本地开发时模拟MaxCompute服务,无需连接实际云服务 - 测试场景 :尤其是端到端(e2e)测试,推荐与TestContainers组件结合使用 - 成本敏感场景 :避免因使用实际MaxCompute服务产生的测试成本 - 资源受限场景 **:在无法访问实际MaxCompute账户的环境中进行功能测试
该项目是典型的SpringBoot应用,可通过以下命令直接运行:
bash# 克隆仓库 git clone [***] # 进入项目目录 cd maxcompute-emulator # 构建项目 ./mvnw install # 运行项目 ./mvnw spring-boot:run
也可直接使用Docker镜像:
bashdocker run -p 8080:8080 maxcompute/maxcompute-emulator:latest
进行端到端测试时,推荐与TestContainers组件结合使用。使用示例如下:
java// 忽略导入 public class MaxComputeEmulatorTest { public static final DockerImageName MAXCOMPUTE_IMAGE = DockerImageName.parse("maxcompute/maxcompute-emulator:v0.0.1"); @ClassRule public static GenericContainer<?> maxcompute = new GenericContainer<>(MAXCOMPUTE_IMAGE) .withExposedPorts(8080) .waitingFor( Wait.forLogMessage(".*Started MaxcomputeEmulatorApplication.*\\n", 1)); public Odps getTestOdps() { Account account = new AliyunAccount("ak", "sk"); Odps odps = new Odps(account); odps.setEndpoint(getEndpoint()); odps.setTunnelEndpoint(getEndpoint()); return odps; } @Test public void test() { Odps odps = getTestOdps(); // 示例:创建表并获取schema Instance instance = SQLTask.run(odps, "create table test(c1 bigint)"); instance.waitForSuccess(); System.out.println(odps.tables().get("test").getSchema()); } private String getEndpoint() { String ip; if (maxcompute.getHost().equals("localhost")) { try { ip = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { ip = "127.0.0.1"; } } else { ip = maxcompute.getHost(); } return "http://" + ip + ":" + maxcompute.getFirstMappedPort(); } }
当使用需要返回当前服务器IP的接口(如Tunnel相关接口)时,服务器默认返回127.0.0.1。但在容器环境中,服务器IP和端口可能随机分配,因此提供了手动上传IP和端口的接口。使用示例如下:
javapublic class MaxComputeEmulatorTest { // 其他代码同上,此处省略 @Test public void test() throws Exception { sendPOST(getEndpoint() + "/init", getEndpoint()); // 其他逻辑 } // 使用Java HTTP客户端发送POST请求,也可使用okhttp等其他HTTP客户端 public static void sendPOST(String postUrl, String postData) throws Exception { URL url = new URL(postUrl); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setDoOutput(true); httpURLConnection.setRequestProperty("Content-Type", "application/json"); httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postData.length())); try (OutputStream outputStream = httpURLConnection.getOutputStream()) { outputStream.write(postData.getBytes("UTF-8")); outputStream.flush(); } int responseCode = httpURLConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { throw new RuntimeException("POST请求失败,响应码: " + responseCode); } } }
欢迎为MaxCompute Emulator贡献代码!如想参与项目贡献,请遵循以下步骤:
如遇到任何问题或需要帮助,请在项目的GitHub Issues页面提交issue。
本项目基于[Apache 2.0]许可 - 详见LICENSE文件。
来自真实用户的反馈,见证轩辕镜像的优质服务
免费版仅支持 Docker Hub 加速,不承诺可用性和速度;专业版支持更多镜像源,保证可用性和稳定速度,提供优先客服响应。
免费版仅支持 docker.io;专业版支持 docker.io、gcr.io、ghcr.io、registry.k8s.io、nvcr.io、quay.io、mcr.microsoft.com、docker.elastic.co 等。
当返回 402 Payment Required 错误时,表示流量已耗尽,需要充值流量包以恢复服务。
通常由 Docker 版本过低导致,需要升级到 20.x 或更高版本以支持 V2 协议。
先检查 Docker 版本,版本过低则升级;版本正常则验证镜像信息是否正确。
使用 docker tag 命令为镜像打上新标签,去掉域名前缀,使镜像名称更简洁。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
在 Linux 系统配置镜像加速服务
在 Docker Desktop 配置镜像加速
Docker Compose 项目配置加速
Kubernetes 集群配置 Containerd
在宝塔面板一键配置镜像加速
Synology 群晖 NAS 配置加速
飞牛 fnOS 系统配置镜像加速
极空间 NAS 系统配置加速服务
爱快 iKuai 路由系统配置加速
绿联 NAS 系统配置镜像加速
QNAP 威联通 NAS 配置加速
Podman 容器引擎配置加速
HPC 科学计算容器配置加速
ghcr、Quay、nvcr 等镜像仓库
无需登录使用专属域名加速
需要其他帮助?请查看我们的 常见问题 或 官方QQ群: 13763429